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

📄 sal_enter_backshiporder.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 4 页
字号:
        DispInfo('退货单号不可重复!',3);
        Edt_InvBillNo.SetFocus;
        abort;
      end;
    end
    else
      begin
        DispInfo('退货单号不可为空!',3);
        Edt_InvBillNo.SetFocus;
        abort;
      end;
    IF Trim(Edt_CustomerCode.Text)='' Then
        begin
          DispInfo('销售客户不能为空!',3);
          Edt_CustomerCode.SetFocus;
          Abort;
        end;

    IF Trim(MEdt_CreateDate.Text)='' Then
    begin
      DispInfo('退货日期不能为空!',3);
      MEdt_CreateDate.SetFocus;
      Abort;
    end;
    if not WHClsPeriodCheck(AdoQry_Tmp,Trim(Edt_WhCode.Text),Copy(MEdt_CreateDate.Text,1,7)) then
    begin
      If Medt_CreateDate.CanFocus then 
      MEdt_CreateDate.SetFocus;
      Abort;
    end;
    
    IF Trim(Edt_TaxRate_Percent.Text)='' Then
    begin
      DispInfo('销售税率不能为空!',3);
      Edt_TaxRate_Percent.SetFocus;
      Abort;
    end;

    IF Trim(Edt_CurrencyCode.Text)='' Then
    begin
      DispInfo('货币不能为空!',3);
      Edt_CurrencyCode.SetFocus;
      Abort;
    end;
  end;
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Text:=' Select CurrencyCode,CurrencyName,IsMaster from Currency '
                      +'          where CurrencyCode= '''+Edt_CurrencyCode.Text+''' ';
  AdoQry_Tmp.Open;
  Edt_CurrencyName.Text := AdoQry_Tmp.fieldbyname('CurrencyName').AsString;
  If AdoQry_Tmp.fieldbyname('IsMaster').AsInteger=1 then ExchRate:=1{如果是本位币则不用判断是否有外币汇率资料}
  else 
  begin
    ExecuteSql(AdoQry_Tmp,' select * from ExchRate  '
                         + '  where CurrencyCode= '+QuotedStr(Edt_CurrencyCode.Text)
                         + '    and ExchMonth= '+QuotedStr(copy(Medt_CreateDate.Text,1,7)),0);
    if AdoQry_tmp.RecordCount=0 then 
    begin
      DispInfo('没有该货币'+Copy(Medt_CreateDate.Text,1,7)+'月的外币汇率!',3);
      If Edt_CurrencyCode.CanFocus then  Edt_CurrencyCode.SetFocus;
      Abort;    
    end;
    ExchRate := AdoQry_Tmp.fieldbyname('ExchRate').AsFloat;
  end;
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能保存!',3);
    Abort;
  end;
  I:=1;
  AdoQry_Body.First;
  While Not AdoQry_Body.Eof Do
  begin
    If StrToFloat(FormatFloat('##0.##',-AdoQry_Body.fieldbyname('InvBillQty').AsFloat))<0 Then
    begin
      DispInfo('第'+IntToStr(I)+'行数据的退货量小于0,不能保存!',3);
      Abort;
    end;
    AdoQry_Body.Next;
     I:=I+1;
  end;
  inherited;
  Application.ProcessMessages;
  DbConnect.beginTrans;
  Try
    AdoQry_Body.First;
    If CurrentFormStatus='Add' Then
    begin
      if edt_InvBillNo.Text='' then
      abort;
      Application.ProcessMessages;
      SqlText:='Insert InvOutBill '
              +' (InvBillNo,ShipType,InvBillDate,InvBillMonth,InvBillCreateTime, '
              +' Sal_EmployeeCode,SaleEmployeeCode,DeptCode, '
              +' CustomerCode,WhCode,WhPositionCode,ShipAddresSCode,ShipModeCode,SaleType,BillTypeCode,CurrencyCode,'
              +' PayTermCode,InvBillTaxRate,TotalInvBillNoTaxAmount,TotalInvBillNoTaxAmountC,TotalInvBillAmount, TotalInvBillAmountC, '
              +' InvBillWhChCk,RemArk,RemArk1)'
              +'  Values('
              +''''+Trim(Edt_InvBillNo.Text)+''','
              +'2,'
              +''''+Trim(MEdt_CreateDate.Text)+''','
              +QuotedStr(Copy(MEdt_CreateDate.Text,1,7))+','
              +QuotedStr(MEdt_CreateDate.Text)+','
              +''''+UserCode+''','
              +iifstring(Trim(Edt_SaleEmployeeCode.Text)='','null',quotedstr(Trim(Edt_SaleEmployeeCode.Text)))+','
              +iifstring(Trim(Edt_SaleDeptCode.Text)='','null',quotedstr(Trim(Edt_SaleDeptCode.Text)))+','
              +iifstring(Trim(Edt_CustomerCode.Text)='','null',quotedstr(Trim(Edt_CustomerCode.Text)))+','
              +QuotedStr(Edt_WhCode.Text)+','
              +QuotedStr(Edt_WhPositionCode.Text)+','
              +iifstring(Trim(Edt_ShipAddresSCode.Text)='','null',quotedstr(Trim(Edt_ShipAddresSCode.Text)))+','
              +iifstring(Trim(Edt_ShipModeCode.Text)='','null',quotedstr(Trim(Edt_ShipModeCode.Text)))+','
              +iifstring(Trim(Edt_SaleTypeCode.Text)='','null',quotedstr(Trim(Edt_SaleTypeCode.Text)))+','
              +QuotedStr(BillTypeCode)+','
              +iifstring(Trim(Edt_CurrencyCode.Text)='','null',quotedstr(Trim(Edt_CurrencyCode.Text)))+','
              +iifstring(Trim(Edt_PayTermCode.Text)='','null',quotedstr(Trim(Edt_PayTermCode.Text)))+','
              +'-('+Trim(Edt_TaxRate_Percent.Text)+'),'
              +'-('+Trim(Edt_TotalNoTaxAmount.Text)+'),'
              +'-('+FormatFloat('#####0.##',ExchRate*StrToFloat(Edt_TotalNoTaxAmount.Text))+'),'
              +'-('+Trim(Edt_TotalTaxAmount.Text)+'),'
              +'-('+FormatFloat('#####0.##',ExchRate*StrToFloat(Edt_TotalTaxAmount.Text))+'),'
              +''''+InttoStr(0)+''','
              +''''+Trim(Edt_RemArk.Text)+''','
              +''''+Trim(Edt_RemArk1.Text)+''')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      ExecuteSql(AdoQry_tmp,'select @@identity as dd',0);
      InvBillId := AdoQry_Tmp.fieldbyname('dd').AsInteger;
      //      saveBackShipOrderHistory(dbconnect,Trim(Edt_InvBillNo.text),userCode,0);
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert InvOutBillLine '
                +' (InvBillId,InvBillLineNo,SloNo,SloLineNo,ItemCode,InvBillQty,'
                +'  BatchNo ,InvBillNoTaxPrice, InvBillNoTaxPriceC,InvBillNoTaxAmount,InvBillNoTaxAmountC, '
                +' InvBillPrice, InvBillPriceC, InvBillAmount, InvBillAmountC ,DiSCountRate,'
                +'  DiSCountAmount,BillLineRemArk)'
                +'Values('
                +IntToStr(InvBillId)+','
                +''''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+''','
                +''''+AdoQry_Body.fieldbyname('SloNo').AsString+''','
                +''''+IntToStr(AdoQry_Body.fieldbyname('SloLineNo').AsInteger)+''','
                +''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','
                +'('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'),'
                +''''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''+','
                +''''+AdoQry_Body.fieldbyname('InvBillNoTaxPrice').AsString+''','
                +FloatToStr(ExchRate*AdoQry_Body.fieldbyname('InvBillNoTaxPrice').AsFloat)+','
                +'('+FormatFloat('#####0.##',AdoQry_Body.fieldbyname('InvBillNoTaxAmount').AsFloat)+'),'
                +'('+FormatFloat('#####0.##',ExchRate*AdoQry_Body.fieldbyname('InvBillNoTaxAmount').AsFloat)+'),'
                +''''+FloatToStr(AdoQry_Body.fieldbyname('InvBillPrice').AsFloat)+''','
                +FloatToStr(ExchRate*AdoQry_Body.fieldbyname('InvBillPrice').AsFloat)+','
                +'('+FormatFloat('#####0.##',AdoQry_Body.fieldbyname('InvBillAmount').AsFloat)+'),'
                +'('+FormatFloat('#####0.##',ExchRate*AdoQry_Body.fieldbyname('InvBillAmount').AsFloat)+'),'
                +''''+AdoQry_Body.fieldbyname('DiSCountRate').AsString+''''+','
                +'('+AdoQry_Body.fieldbyname('DiSCountAmount').AsString+'),'
                +''''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
           //     +' '''' '+','
                +')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
//        saveBackShipOrderLineHistory(dbconnect,Trim(Edt_InvBillNo.text),AdoQry_Body.fieldbyname('InvBillLineNo').asinteger,userCode,0);
        AdoQry_Body.Next;
      end;
    end;
    If CurrentFormStatus='Edit' Then
    begin
//      saveBackShipOrderHistory(dbconnect,Trim(Edt_InvBillNo.text),userCode,1);
      SqlText:='Update InvOutBill '
              +' Set InvBillNo='''+Trim(Edt_InvBillNo.Text)+''','
              +'     SaleEmployeeCode= '''+Trim(Edt_SaleEmployeeCode.Text)+''','
              +'     DeptCode= '+iifstring(Trim(Edt_SaleDeptCode.Text)='','null',quotedstr(Trim(Edt_SaleDeptCode.Text)))+','
              +'     CustomerCode='+iifstring(Trim(Edt_CustomerCode.Text)='','null',quotedstr(Trim(Edt_CustomerCode.Text)))+','
              +'     ShipAddresSCode= '+iifstring(Trim(Edt_ShipAddresSCode.Text)='','null',quotedstr(Trim(edt_ShipAddresSCode.text)))+','
              +'     ShipModeCode= '+iifstring(Trim(Edt_ShipModeCode.Text)='','null',quotedstr(Trim(Edt_ShipModeCode.Text)))+','
              +'     SaleType= '+iifstring(Trim(Edt_SaleTypeCode.Text)='','null',quotedstr(Trim(Edt_SaleTypeCode.Text)))+','
              +'     CurrencyCode= '+iifstring(Trim(Edt_CurrencyCode.Text)='','null',quotedstr(Trim(Edt_CurrencyCode.Text)))+','
              +'     PayTermCode= '+iifstring(Trim(Edt_PayTermCode.Text)='','null',quotedstr(Trim(Edt_PayTermCode.Text)))+','
              +'     InvBillTaxRate = '''+Trim(Edt_TaxRate_Percent.Text)+''','
              +'     TotalInvBillNoTaxAmount= -('+Trim(Edt_TotalNoTaxAmount.Text)+'),'
              +'     TotalInvBillNoTaxAmountC=Convert(decimal(20,2),ExchRate*(-('+Edt_TotalNoTaxAmount.Text+'))),'
              +'     TotalInvBillAmount= -('+Trim(Edt_TotalTaxAmount.Text)+'),'
              +'     TotalInvBillAmountC=Convert(Decimal(20,2),ExchRate*(-('+Edt_TotalTaxAmount.Text+'))),'
              +'     RemArk= '''+Trim(Edt_RemArk.Text)+''','
              +'     RemArk1= '''+Trim(Edt_RemArk1.Text)+''''
              +'     Where InvBillNo='''+Trim(Edt_InvBillNo.Text)+'''';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
//        saveBackShipOrderLineHistory(dbconnect,Trim(Edt_InvBillNo.text),AdoQry_Body.fieldbyname('InvBillLineNo').asinteger,userCode,1);
        ExecuteSql(AdoQry_Tmp,'select ExchRate from InvOutBill where InvBillNo='+QuotedStr(Edt_InvBillNo.Text),0)        ;
        SqlText:=' UpDate InvOutBillLine '
                +' Set '
                +' SloNo='''+AdoQry_Body.fieldbyname('SloNo').AsString+''','
                +' SloLineNo='''+IntToStr(AdoQry_Body.fieldbyname('SloLineNo').AsInteger)+''','
                +' ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''','
                +' InvBillQty=('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'),'
                +' InvBillNoTaxPrice='''+AdoQry_Body.fieldbyname('InvBillNoTaxPrice').AsString+''','
                +' InvBillNoTaxPriceC='+AdoQry_Tmp.fieldbyname('ExchRate').AsString+'*('+AdoQry_Body.fieldbyname('InvBillNoTaxPrice').AsString+'),'
                +' InvBillNoTaxAmount=('+FormatFloat('######0.##',AdoQry_Body.fieldbyname('InvBillNoTaxAmount').AsFloat)+'),'
                +' InvBillNoTaxAmountC=Convert(decimal(20,2),'+AdoQry_Tmp.fieldbyname('ExchRate').AsString+'*(('+AdoQry_Body.fieldbyname('InvBillNoTaxAmount').AsString+'))),'
                +' InvBillPrice='''+FloatToStr(AdoQry_Body.fieldbyname('InvBillPrice').AsFloat)+''','
                +' InvBillPriceC='+AdoQry_Tmp.fieldbyname('ExchRate').AsString+'*('+AdoQry_Body.fieldbyname('InvBillPrice').AsString+'),'
                +' DiSCountRate='''+AdoQry_Body.fieldbyname('DiSCountRate').AsString+''','
                +' DiSCountAmount=('+AdoQry_Body.fieldbyname('DiSCountAmount').AsString+'),'
                +' BillLineRemArk='''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''','
                +' BatchNo='''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''+','
                +' InvBillAmountC=Convert(decimal(20,2),'+AdoQry_Tmp.fieldbyname('ExchRate').AsString+'*(('+AdoQry_Body.fieldbyname('InvBillAmount').AsString+'))),'
                +' InvBillAmount=('+FormatFloat('#####0.##',AdoQry_Body.fieldbyname('InvBillAmount').AsFloat)+')'

                +' Where InvBillId='+AdoQry_Body.fieldbyname('InvBillId').AsString
                +' And InvBillLineNo='''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+'''';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
        AdoQry_Body.Next;
      end;
    end;
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;
    DispInfo('数据保存成功!',3);
  Except
   on e:exception do
    begin
    DbConnect.RollBackTrans;
    recOrderror(self,AdoQry_tmp,e.message);
    Edt_InvBillNo.Text:='';
    DispInfo('保存数据失败,请重试!',1);
    Abort;
    end;
  end;
  with Frm_Sal_Enter_BackShipOrderH.AdoQry_Head do
  begin
    If CurrentFormStatus='Add' Then
      Append
    else
      edit;
    fieldbyname('InvBillNo').AsString:=Edt_InvBillNo.Text;
    fieldbyname('CustomerCode').AsString:=Edt_CustomerCode.Text;
    fieldbyname('CustomerName').AsString:=Lab_CustomerName.Text ;
    fieldbyname('TotalInvBillAmount').AsString:=Edt_TotalTaxAmount.Text;
    fieldbyname('TotalInvBillNoTaxAmount').AsString:=Edt_TotalNOTaxAmount.Text;
    If CurrentFormStatus='Add' Then
    begin
      fieldbyname('Sal_EmployeeCode').AsString:=UserCode;
      fieldbyname('InvBillDate').Asstring:=MEdt_CreateDate.Text;
    end        ;
    fieldbyname('DeptCode').AsString:=Edt_SaleDeptCode.Text;
    fieldbyname('DeptName').AsString:=Lab_SaleDeptName.Caption;

    fieldbyname('WhCode').AsString:=Edt_WhCode.Text;
    fieldbyname('WhName').AsString:=Edt_WhName.Text;

    fieldbyname('WhPositionCode').AsString:=Edt_WhPositionCode.Text;
    fieldbyname('WhPositionName').AsString:=Edt_WhPositionName.Text;

    fieldbyname('SaleType').AsString:=Edt_SaleTypeCode.Text;
    fieldbyname('SaleTypeName').AsString:=Edt_SaleTypeName.Text;    
    fieldbyname('SaleEmployeeCode').AsString:=Edt_SaleEmployeeCode.Text;
    fieldbyname('EmployeeName').AsString:= Edt_SaleEmployeeName.Text ;
    fieldbyname('CreateEmployeeName').AsString:= Label20.Caption;


    fieldbyname('CurrencyCode').AsString:=Edt_CurrencyCode.Text;
    fieldbyname('CurrencyName').AsString:=Lab_CurrencyName.Caption;

    fieldbyname('InvBillTaxRate').AsString:=Edt_TaxRate_Percent.Text;
    fieldbyname('ShipModeCode').AsString:=Edt_ShipModeCode.Text;
    fieldbyname('ShipModeName').AsString:=Lab_ShipModeName.Caption;

    fieldbyname('ShipAddresSCode').AsString:=Edt_ShipAddresSCode.Text;
    fieldbyname('ShipAddressName').AsString:=Edt_ShipAddressName.Text ;

    fieldbyname('PayTermCode').AsString:=Edt_PayTermCode.Text;
    fieldbyname('PayTermName').AsString:=Edt_SaleTermName.Text;

    fieldbyname('RemArk').AsString:=Edt_RemArk.Text;
    fieldbyname('RemArk1').AsString:=Edt_RemArk1.Text;
    post;
  end;
end;

procedure TFrm_Sal_Enter_BackShipOrder.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('InvBillAmount').asfloat;
     TotalNoTaxAmount:= TotalNoTaxAmount +AdoQry_Body.fieldbyname('InvBillNoTaxAmount').asfloat;
     AdoQry_Body.Next;
  end;
 if  AdoQry_Body.RecordCount >0 then
    AdoQry_Body.BookMArk:=BookMArk;

  Edt_TotalNoTaxAmount.Text:= FormatFloat('#####0.##',-TotalNoTaxAmount);
  Edt_TotalTaxAmount.Text:= FormatFloat('#####0.##',-TotalTaxAmount);
end;


procedure TFrm_Sal_Enter_BackShipOrder.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
  if Currentstatus='Add' then
  begin
    AnswerStatus:='Add';
    EnableControls:='Edt_InvBillNo,Edt_CustomerCode,Edt_CustomerName,'//Edt_CreateEmployeeCode,'
                   +' MEdt_CreateDate, Edt_SaleDeptCode, Edt_SaleTypeCode,'
                   +' Edt_SaleEmployeeCode, Edt_CurrencyCode, Edt_TaxRate_Percent,'
                   +' Edt_ShipModeCode, Edt_ShipAddresSCode, Edt_PayTermCode,'
                   +' Edt_RemArk,Edt_RemArk1,Edt_InvoiceNo,Cx_Assess,Edt_AssessorEmployeeCode,';
  end
  Else If Pos('Edit',CurrentStatus)>0 Then
  begin
    AnswerStatus:='PArtEdit';
    EnableControls:=' Edt_CustomerCode,Edt_CustomerName,'//Edt_CreateEmployeeCode,'
                   +' MEdt_CreateDate, Edt_SaleDeptCode, Edt_SaleTypeCode,'
                   +' Edt_SaleEmployeeCode, Edt_CurrencyCode, Edt_TaxRate_Percent,'
                   +' Edt_ShipModeCode, Edt_ShipAddresSCode, Edt_PayTermCode,'
                   +' Edt_RemArk,Edt_RemArk1,Edt_InvoiceNo,Cx_Assess,Edt_AssessorEmployeeCode,';
  end;

end;

procedure TFrm_Sal_Enter_BackShipOrder.Act_DeleteLineExecute(Sender: TObject);
var
  BookMArk:String;
begin
  if (not AdoQry_Body.IsEmpty)and
     (DispInfo(' 真的删除当前记录吗? ',2)='y') then
    AdoQry_Body.Delete;
  If  AdoQry_Body.RecordCount>0 Then
  begin
    BookmArk:=AdoQry_Body.BookmArk;
    AdoQry_Body.First;

⌨️ 快捷键说明

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