⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sal_enter_passbackshiporder.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
                +' TotalInvBillAmountC,InvBillWhChCk,RemArk1,SourceNo)'
               +' select '+QuotedStr(OutBillNo)+','
                          +' InvBillDate, '
                          +' InvBillMonth,'
                          +' InvBillCreateTime,Sal_EmployeeCode,SaleEmployeeCode,DeptCode, '
                          +' CustomerCode,WhCode,WhPositionCode,ShipAddresSCode,ShipModeCode,SaleType, '
                          +' case BillTypeCode when ''0205'' then ''0203'' '
                          +'                   when ''0206'' then ''0204'' '
                          +' end, '
                          +' CurrencyCode, '
                          +' PayTermCode,InvBillTaxRate,ExchRate,TotalInvBillNoTaxAmount,TotalInvBillAmount,TotalInvBillNoTaxAmountC, '
                          +' TotalInvBillAmountC,InvBillWhChCk,RemArk1,InvBillNo '
               +' from InvOutBill '
               +' Where InvBillNo = '+QuotedStr(ShipNo);
    ExecuteSql(AdoQry,SqlText,1);
    ExecuteSql(AdoQry,'Select * from InvOutBill '
                         +' where InvBillNo='+QuotedStr(OutBillNo),0)    ;
    InvBillId := AdoQry.fieldbyname('InvBillId').AsInteger;

    SqlText:='Insert InvOutBillLine '
            +' (InvBillId,InvBillLineNo,SloNo,SloLineNo,ItemCode,InvBillQty,InvBillNoTaxPrice,InvBillNoTaxPriceC,'
            +'  InvBillNoTaxAmount,InvBillNoTaxAmountC,InvBillPrice, InvBillPriceC,'
            +' InvBillAmount, InvBillAmountC,DiSCountRate,DiSCountAmount,BillLineRemArk,BatchNo)'
            +' select '+IntToStr(InvBillId)+','
                       +' InvBillLineNo,SloNo,SloLineNo,ItemCode,InvBillQty,InvBillNoTaxPrice,InvBillNoTaxPriceC,'
                       +' InvBillNoTaxAmount,InvBillNoTaxAmountC,InvBillPrice,InvBillPriceC,'
                       +'  InvBillAmount,InvBillAmountC,InvOutBillLine.DiSCountRate,InvOutBillLine.DiSCountAmount,BillLineRemArk,BatchNo '
            +'  from InvOutBillLine '
            +' Join InvOutBill On InvOutBillLIne.InvBillId=InvOutBill.InvBillId and InvOutBill.InvBillNo = '+QuotedStr(ShipNo);

    ExecuteSql(AdoQry,SqlText,1);
    Result := InvBillId;
  Finally
    If Assigned(AdoQry) then   AdoQry.Free;
  end;  
end;

procedure TFrm_Sal_Enter_PassBackShipOrder.Act_CancelCheckExecute(
  Sender: TObject);
var
  SqlText:String;
begin
  inherited;
  If (AdoQry_Head.Eof) And (AdoQry_Head.Bof) Then
    Exit;
  If  Cx_Assess.ItemIndex = 1 then
    If (DispInfo('确认真的要取消审核这张销售退货单吗?',2)='y') Then
    begin
      try
        Dbconnect.beginTrans ;
        Addqty;
        saveBackShipOrderHistory(dbconnect,edt_Shipno.text,userCode,4);
        SQlText:=' UpDate Sa_BackShipOrder Set Assess=0, '
                +' AssessorEmployeeCode=''''  Where BackShipNo='''+Edt_ShipNo.Text+''' ';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.sql.clear ;
        AdoQry_Tmp.SQL.Text := SqlText;
        AdoQry_Tmp.ExecSQL ;
        AdoQry_Head.Edit;
        AdoQry_Head.fieldbyname('Assess').AsInteger:=0;
        AdoQry_Head.fieldbyname('AssessorEmployeeCode').AsString:='';
        AdoQry_Head.Post;
        Cx_Assess.ItemIndex :=0;
        Edt_AssessorEmployeeCode.Text := '';
        edt_assessName.Text:='' ;
        Dbconnect.CommitTrans;
      except
        if dbconnect.InTransaction then dbconnect.RollBackTrans;
          DispInfo('弃审失败!',3);
      end;
    end;
end;


function  TFrm_Sal_Enter_PassBackShipOrder.judgeShipqty:boolean;
var sqltext:string;
begin
  Result:=False;
  AdoQry_Body.First;
  while not AdoQry_Body.Eof do
  begin
    If -AdoQry_Body.fieldbyname('InvBillQty').AsFloat<=0 then
    begin
      If Dbconnect.InTransaction then dbconnect.RollBackTrans;
      DispInfo('第'+inttostr(AdoQry_Body.recno)+'行数据退货数量必须大于0!',3);
      Dbgrideh.SetFocus;
      abort;
    end; 
    sqltext:='select InvBillqty,isnull(BackShipqty,0)  as BackShipqty,slono,slolineno from InvOutBillLine '
            +'  join InvOutBill on InvOutBillLine.InvBillId = InvOutBill.InvBillId '
            +' where InvBillNo ='+QuotedStr(AdoQry_Body.fieldbyname('SloNo').AsString)
            +'   and InvBillLineNo='+inttostr(AdoQry_Body.fieldbyname('SloLineNo').asinteger);
    Executesql(AdoQry_tmp,sqltext,0);
    slono:=AdoQry_tmp.fieldbyname('slono').asstring;
    slolineno:=AdoQry_tmp.fieldbyname('slolineno').asinteger;
    if AdoQry_tmp.fieldbyname('InvBillqty').asfloat<AdoQry_tmp.fieldbyname('BackShipqty').asfloat+(-AdoQry_Body.fieldbyname('InvBillqty').asfloat) then
      begin
        If Dbconnect.InTransaction then dbconnect.RollBackTrans;
        DispInfo('第'+inttostr(AdoQry_Body.recno)+'行数据退货总量超过了销售发货总量!',3);
        abort;
      end;
    if slono<>'' then
      begin
        sqltext:='select * from sa_SaleOrderline'
                +' where slono='+quotedstr(slono)
                +'   and slolineno='+inttostr(slolineno);
        Executesql(AdoQry_tmp,sqltext,0);
        if AdoQry_tmp.fieldbyname('slolinestatus').asinteger<2 then
         begin
            if dbconnect.InTransaction  then dbconnect.RollBackTrans;
            DispInfo('第'+inttostr(AdoQry_Body.recno)+'行数据销售订单未审核,不能退货!',3);
            Result:=True;
            abort;
         end;
         sqltext:='update sa_SaleOrderline'
                +'  set  Shipqty=IsNull(Shipqty,0)+('+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+')'
                +' where slono='+quotedstr(slono)
                +'  and slolineno='+inttostr(slolineno);
         Executesql(AdoQry_tmp,sqltext,1);
         SqlText := 'update InvOutBillLine '
                    +' set InvBillQty=('+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'),'
                    +'     InvBillAmount='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillPrice, '
                    +'     InvBillAmountC='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillPriceC, '
                    +'     InvBillNoTaxAmountC='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillNoTaxPriceC, '
                    +'     InvBillNoTaxAmount='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillNoTaxPrice '
                    +' where InvBillId = '+AdoQry_Body.fieldbyname('InvBillId').AsString
                    +'  and  InvBillLineNo = '+AdoQry_BoDy.fieldbyname('InvBillLineNo').asString;;
         ExecuteSql(AdoQry_Tmp,sqltext,1)            ;
         sqltext:='update InvOutBillLine'
                +'  set  BackShipqty=isnull(BackShipqty,0)+(('+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'))' 
                +' from InvOutBillLIne,InvOutBill '
                +' where InvOutBillLIne.InvBillId=InvOutBill.InvBillId '
                +'  and InvBillNo='+quotedstr(AdoQry_Body.fieldbyname('Slono').asstring)
                +'  and InvBilllineno='+inttostr(AdoQry_Body.fieldbyname('Slolineno').asinteger);
         Executesql(AdoQry_tmp,sqltext,1);
       end;
      SqlText:=' Update Item With(RowLock) '
              +'   Set CurrentOnHandInv=IsNull(CurrentOnhandInv,0)-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')'
              +'  where ItemCode='+QuotedStr(AdoQry_Body.fieldbyname('ItemCode').AsString);
      Executesql(AdoQry_Tmp,SqlText,1)                ;
      SqlText := 'select * from CurrentInv '
               +' where WhCode='+QuotedStr(Edt_WhCode.Text)
               +'   and WhPositionCode =' +QuotedStr(Edt_WhPositionCode.Text)
               +'   and ItemCode =' +QuotedStr(AdoQry_Body.fieldbyname('ItemCode').AsString)
               +'  if @@RowCount>0 ' 
               +'  begin '
               +'    Update CurrentInv '
               +'      Set OnHandInv = IsNull(OnHandInv,0)-(' +AdoQry_Body.fieldbyname('InvBillQty').AsString+')'
               +'     where WhCode='+QuotedStr(Edt_WhCode.Text)
               +'       and WhPositionCode =' +QuotedStr(Edt_WhPositionCode.Text)
               +'       and ItemCode =' +QuotedStr(AdoQry_Body.fieldbyname('ItemCode').AsString)
               +'    end '
               +'   else  '
               +'   begin '
               +'     Insert Into CurrentInv(WhCode,WhPositionCode,OnhandInv) '
               +'      Values ('+QuotedStr(Edt_WhCode.Text)+','
                                +QuotedStr(Edt_WhPositionCode.Text)+','
                                +'-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')'
               +'                 )  '
               +'     end ';
      ExecuteSql(AdoQry_Tmp,SqlText,1);
     AdoQry_Body.Next;
  end;
  SqlText := 'update InvOutBill '
                  +' set  TotalInvBillAmount=-('+Edt_TotalTaxAmount.Text +'),'
                  +'     TotalInvBillAmountC=ExchRate*(-('+Edt_TotalTaxAmount.Text+')),'
                  +'     TotalInvBillNoTaxAmountC=ExchRate*(-('+Edt_TotalNoTaxAmount.Text+')),'
                  +'     TotalInvBillNoTaxAmount=-('+Edt_TotalNoTaxAmount.Text+')'
                  +' where InvBillNo = '+QuotedStr(Edt_ShipNo.Text);
  ExecuteSql(AdoQry_tmp,SqlText,1);
  Result:=True;
end;

function  TFrm_Sal_Enter_PassBackShipOrder.Addqty:boolean;
var sqltext:string;
begin
  Result:=False;
  AdoQry_Body.First;
  while not AdoQry_Body.Eof do
  begin
    sqltext:='select Shipqty,isnull(BackShipqty,0)  as BackShipqty,slono,slolineno from sa_ShipOrderline '
            +' where Shipno='+quotedstr(AdoQry_Body.fieldbyname('Shipno').asstring)
            +'   and Shiplineno='+inttostr(AdoQry_Body.fieldbyname('Shiplineno').asinteger);
    Executesql(AdoQry_tmp,sqltext,0);
    slono:=AdoQry_tmp.fieldbyname('slono').asstring;
    slolineno:=AdoQry_tmp.fieldbyname('slolineno').asinteger;
    if slono<>'' then
      begin
        sqltext:=' update sa_SaleOrderline'
                +'  set  Shipqty=Shipqty+'+floattostr(AdoQry_Body.fieldbyname('Shipqty').asfloat)
                +' where slono='+quotedstr(slono)
                +'  and slolineno='+inttostr(slolineno);
        Executesql(AdoQry_tmp,sqltext,1);
        sqltext:=' update sa_ShipOrderline'
                +'  set  BackShipqty=isnull(BackShipqty,0)-'+floattostr(AdoQry_Body.fieldbyname('Shipqty').asfloat)
                +' where Shipno='+quotedstr(AdoQry_Body.fieldbyname('Shipno').asstring)
                +'  and Shiplineno='+inttostr(AdoQry_Body.fieldbyname('Shiplineno').asinteger);
        Executesql(AdoQry_tmp,sqltext,1);
      end;
    AdoQry_Body.Next;
  end;
  Result:=True;
end;

procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyAfterPost(
  DataSet: TDataSet);
var
  TotalNoTaxAmount,TotalTaxAmount:double;
  BookMArk:String;
begin
  inherited;
  TotalNoTaxAmount:=0;
  TotalTaxAmount:=0;
  if  AdoQry_Body.RecordCount >0 then
    BookMArk:=AdoQry_Body.BookMArk;
  AdoQry_Body.First;
  while not AdoQry_Body.Eof do
  begin
     TotalTaxAmount:= TotalTaxAmount +AdoQry_Body.fieldbyname('InvBillQty').asfloat*AdoQry_Body.fieldbyname('InvBillPrice').AsFloat;
     TotalNoTaxAmount:= TotalNoTaxAmount +AdoQry_Body.fieldbyname('InvBillQty').asfloat*AdoQry_Body.fieldbyname('InvBillNoTaxPrice').AsFloat;
     AdoQry_Body.Next;
  end;
 if  AdoQry_Body.RecordCount >0 then
    AdoQry_Body.BookMArk:=BookMArk;

  Edt_TotalNoTaxAmount.Text:= floattostr(-TotalNoTaxAmount);
  Edt_TotalTaxAmount.Text:= floattostr(-TotalTaxAmount);
end;

procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyBeforeInsert(
  DataSet: TDataSet);
begin
  inherited;
  Abort;
end;


procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyInvBillQtyGetText(
  Sender: TField; var Text: String; DisplayText: Boolean);
begin
  inherited;
  Text := FloatToStr(-AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
end;

procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyInvBillAmountGetText(
  Sender: TField; var Text: String; DisplayText: Boolean);
begin
  inherited;
  Text := FloatToStr(-AdoQry_Body.fieldbyname('InvBillAmount').AsFloat);

end;

procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyInvBillNoTaxAmountGetText(
  Sender: TField; var Text: String; DisplayText: Boolean);
begin
  inherited;
  Text := FloatToStr(-AdoQry_Body.fieldbyname('InvBillNoTAxAmount').AsFloat);

end;

procedure TFrm_Sal_Enter_PassBackShipOrder.AdoQry_BodyDiSCountAmountGetText(
  Sender: TField; var Text: String; DisplayText: Boolean);
begin
  inherited;
  Text := FloatToStr(-AdoQry_Body.fieldbyname('DiSCountAmount').AsFloat);

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -