GetPVmin(VAR SalesLine : Record "Sales Line";ShipAgent : Code[20];Contacto : Code[20];ShipPostCode : Code[20];Country : Code[10]) : Decimal SalesLine.SETFILTER(Type,'<>0'); IF SalesLine.FINDSET THEN BEGIN IF SalesLine."Document Type"<>SalesLine."Document Type"::Order THEN EXIT; ltcontact.GET(Contacto); IF NOT ltTabDiv.GET('RUBCUSTO',0,'TAXAJURO') THEN EXIT; ltLocation.GET(SalesLine."Location Code"); IF ltLocation."Country/Region Code"='' THEN ltLocation."Country/Region Code":='PT'; IF Country='' THEN Country:='PT'; KgTotais:=0; distancia:=GetDist(ltLocation."Post Code",ShipPostCode,ltLocation."Country/Region Code",Country); REPEAT IF NOT SalesLine."Item Container" THEN KgTotais+=SalesLine.Quantity ELSE BEGIN //Vasilhame:=SalesLine.Quantity; ltValueEntry."Entry No.":=SalesLine."Attached to Line No."; ltValueEntry."Item No.":=SalesLine."No."; ltValueEntry."Valued Quantity":=SalesLine.Quantity; ltValueEntry.INSERT; END; UNTIL SalesLine.NEXT=0; SalesLine.SETRANGE("Item Container",FALSE); //roliveira 2017-10-04 begin VVasilhame:=0; IF SalesLine.FINDSET THEN REPEAT SalesLine2:=SalesLine; SalesLine.SETRANGE("Item Container"); SalesLine.SETRANGE("Document Type", SalesLine."Document Type"); SalesLine.SETFILTER("Document No.", SalesLine."Document No."); SalesLine.SETRANGE("Attached to Line No.", SalesLine."Line No."); QProduto:=0; QVasilhame:=0; IF SalesLine.FINDFIRST THEN BEGIN QProduto:=SalesLine2.Quantity; QVasilhame:=SalesLine.Quantity; END; IF QVasilhame<>0 THEN VVasilhame:=QProduto/QVasilhame ELSE VVasilhame:=1; SalesLine.SETRANGE("Attached to Line No."); SalesLine.SETRANGE("Item Container",FALSE); SalesLine.GET(SalesLine2."Document Type",SalesLine2."Document No.",SalesLine2."Line No."); SalesLine."Custo Operação":=GetCustoOperacao(SalesLine."No.",SalesLine."Variant Code")/VVasilhame; IF SalesLine."Codigo Vasilhame"<>'' THEN BEGIN SalesLine."Custo Vasilhame":=GetCustoVasilhame(SalesLine."Codigo Vasilhame",0,SalesLine."Vasilhame Devolver")/VVasilhame; END; SalesLine."Custo Stock":=GetCustoStock(SalesLine."No."); SalesLine."Custo Fornecedor":=GetCustoFornecedor(SalesLine."No."); SalesLine."Custo Transporte":=GetCustoTransporte(ShipAgent,ltLocation.Code,KgTotais,distancia,COPYSTR(ShipPostCode,1,2)); SalesLine."Custo Transferencia":=GetCustoTransferencia(ltLocation.Code); ltitem.GET(SalesLine."No."); SalesLine."Unit Cost":=ltitem."Unit Cost"; SalesLine."PV Minimo":=(ltitem."Unit Cost"+SalesLine."Custo Operação"+SalesLine."Custo Vasilhame"+SalesLine."Custo Stock"-SalesLine."Custo Fornecedor"+SalesLine."Custo Transporte"+SalesLine."Custo Transferencia") /(1-ltTabDiv.Custo*GETdiasCliente(Contacto)/365-GetMargemMin(SalesLine."No.",ltcontact.Segmentacao,SalesLine.Quantity)); SalesLine."PV Aconselhado":=(ltitem."Unit Cost"+SalesLine."Custo Operação"+SalesLine."Custo Vasilhame"+SalesLine."Custo Stock"-SalesLine."Custo Fornecedor"+SalesLine."Custo Transporte"+SalesLine."Custo Transferencia") /(1-ltTabDiv.Custo*GETdiasCliente(Contacto)/365-GetMargemDef(SalesLine."No.",ltcontact.Segmentacao,SalesLine.Quantity)); SalesLine."Custo Cliente":=SalesLine."PV Minimo"*ltTabDiv.Custo*GETdiasCliente(Contacto)/365; SalesLine.Margem:=GetMargemMin(SalesLine."No.",ltcontact.Segmentacao,SalesLine.Quantity)*SalesLine."PV Minimo"; GetUltimaVenda(SalesLine); GetUltimaProposta(SalesLine); SalesLine.MODIFY; UNTIL SalesLine.NEXT=0; END; SalesLine.RESET; SalesLine.SETRANGE("Document Type",SalesLine."Document Type"); SalesLine.SETRANGE("Document No.",SalesLine."Document No.");