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

📄 sal_enter_othershiporder.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 5 页
字号:
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text:=SqlText;
    AdoQry_Tmp.Open;
    If  not AdoQry_Tmp.Eof then
    begin
      DispInfo('销售发货单号不可重复!',3);
      Edt_ShipNo.SetFocus;
      abort;
    end;
  end
  else
    begin
      DispInfo('销售发货单号不可为空!',3);
      Edt_ShipNo.SetFocus;
      abort;
    end;

  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能保存!',3);
    Abort;
  end;
  I:=1;
//  inherited;
  Application.ProcessMessages;
  DbConnect.beginTrans;
  Try
    AdoQry_Body.First;
    If CurrentFormStatus='Add' Then
    begin
      if edt_ShipNo.Text='' then
      abort;
      Application.ProcessMessages;
            SqlText:='Insert InvOutBill '
              +' (InvBillNo,InvBillDate,InvBillMonth,InvBillCreateTime,Sal_EmployeeCode,SaleEmployeeCode,DeptCode, '
              +' CustomerCode,WhCode,WhPositionCode,ShipAddresSCode,ShipModeCode,SaleType,ShipType,BillTypeCode,CurrencyCode,'
              +' PayTermCode,InvBillTaxRate,TotalInvBillNoTaxAmount,TotalInvBillAmount,ExchRate,TotalInvBillNoTaxAmountC,TotalInvBillAmountC, '
              +' InvBillWhChCk,RemArk1,RemArk)'
              +'  Values('
              +''''+Trim(Edt_ShipNo.Text)+''','
              +''''+Trim(MEdt_CreateDate.Text)+''','
              +QuotedStr(Copy(MEdt_CreateDate.Text,1,7))+','
              +''''+Trim(MEdt_CreateDate.Text)+''','
              +''''+UserCode+''','
              +''''+Trim(Edt_SaleEmployeeCode.Text)+''','
              +''''+Trim(Edt_SaleDeptCode.Text)+''','
              +''''+Trim(Edt_CustomerCode.Text)+''','
              +Quotedstr(Edt_WhCode.Text)+','
              +QuotedStr(Edt_WhPositionCode.Text)+','
              +''''+Trim(Edt_ShipAddresSCode.Text)+''','
              +''''+Trim(Edt_ShipModeCode.Text)+''','
              +''''+Trim(Edt_SaleTypeCode.Text)+''','
              +'1,'
              +QuotedStr(IIFValue(Cmb_BillType.ItemIndex=0,'0205','0206'))+','
              +''''+Trim(Edt_CurrencyCode.Text)+''','
              +iifString(Trim(Edt_PayTermCode.Text)='','null',quotedstr(Trim(Edt_PayTermCode.Text)))+','
              +''''+Trim(Edt_TaxRate_Percent.Text)+''','
              +''''+Trim(Edt_TotalNoTaxAmount.Text)+''','
              +''''+Trim(Edt_TotalTaxAmount.Text)+''','
              +FloatToStr(ExchRate)+','
              +FormatFloat('#####0.##',ExchRate*StrToFloat(Edt_TotalNoTaxAmount.Text))+','
              +FormatFloat('#####0.##',ExchRate*StrToFloat(Edt_TotalTaxAmount.Text))+','
              +' 0,'
              +''''+Trim(Edt_RemArk1.Text)+''','
              +''''+Trim(Edt_RemArk.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;
    //  SaveSa_SaleOrderHistory(dbconnect,Trim(edt_SloNo.text),userCode,0);
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert InvOutBillLine '
                +' (InvBillId,InvBillLineNo,SloNo,SloLineNo,ItemCode,InvBillQty,InvBillNoTaxPrice,InvBillNoTaxPriceC, '
                +' InvBillNoTaxAmount, InvBillNoTaxAmountC, InvBillPrice, InvBillPriceC,'
                +' InvBillAmount, InvBillAmountC,DiSCountRate,DiSCountAmount,BillLineRemArk,BatchNo)'
                +'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('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_Body.fieldbyname('BatchNo').AsString+''''
                +')';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
//        saveShipOrderLineHistory(dbconnect,Trim(edt_Shipno.text),AdoQry_Body.fieldbyname('Shiplineno').asinteger,userCode,0);
        SqlText:=' Update Sa_SaleOrderLine Set PrepareShipQty='''+AdoQry_Body.fieldbyname('InvBillQty').AsString+''' '
                +' Where  SloNo='''+AdoQry_Body.fieldbyname('SloNo').AsString+''' '
                +'   And  SloLineNo='''+IntToStr(AdoQry_Body.fieldbyname('SloLineNo').AsInteger)+'''';
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.Text:=SqlText;
        AdoQry_Tmp.ExecSQL;
       // SaveSa_SaleOrderLineHistory(dbconnect,Trim(edt_SloNo.text),AdoQry_Body.fieldbyname('SloLineNo').asinteger,userCode,0);
        AdoQry_Body.Next;
      end;
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.clear;
      AdoQry_Tmp.SQL.Text := ' Select SalParamValueN from  Sa_SalParam Where SalParamCode=''ShiPassess'' ';
      AdoQry_Tmp.Open;
      if AdoQry_Tmp.fieldbyname('SalParamValueN').AsFloat = 0 then
      begin
        updateqty(0);
        AdoQry_Tmp.Close;
        AdoQry_Tmp.SQL.clear;
        AdoQry_Tmp.SQL.Text := ' Update InvOutBill Set InvBillWhChck=1,'
                              +'   Wh_EmployeeCode='''+UserCode+''' '
                              +'   Where InvBillNo='''+Edt_ShipNo.Text+'''';
        AdoQry_Tmp.ExecSQL;
      end;
      
    end;

    If CurrentFormStatus='PArtEdit' Then
    begin
    //  SaveSa_SaleOrderHistory(dbconnect,Trim(edt_SloNo.text),userCode,1);
   // saveShipOrderHistory(dbconnect,Trim(edt_Shipno.text),userCode,1);
      ExecuteSql(AdoQry_Tmp,'select * from InvOutBill '
                           +' where InvBillWhChCk=0 '
                           +'   and InvBillNo='+QuotedStr(Edt_ShipNo.Text),0);
      if AdoQry_Tmp.RecordCount=0 then 
      begin
        DispInfo('该单据已审核或被删除,不能修改!',3);
        Abort;
      end;
      SqlText:='Update InvOutBill '
              +' Set InvBillNo='''+Trim(Edt_ShipNo.Text)+''','
              +' InvBillDate= '''+Trim(MEdt_CreateDate.Text)+''','
              +' SaleEmployeeCode= '''+Trim(Edt_SaleEmployeeCode.Text)+''','
              +' DeptCode= '''+Trim(Edt_SaleDeptCode.Text)+''','
              +' ShipAddresSCode= '''+Trim(Edt_ShipAddresSCode.Text)+''','
              +' ShipModeCode= '''+Trim(Edt_ShipModeCode.Text)+''','
              +' SaleType= '''+Trim(Edt_SaleTypeCode.Text)+''','
              +' CurrencyCode= '''+Trim(Edt_CurrencyCode.Text)+''','
              +' PayTermCode= '''+Trim(Edt_PayTermCode.Text)+''','
              +' BillTypeCode='+QuotedStr(IIFValue(Cmb_BillType.ItemIndex=0,'0205','0206'))+','
              +' 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)+''','
              +' CustomerCode='''+Edt_CustomerCode.Text+''''

              +' Where InvBillNo='''+Trim(Edt_ShipNo.Text)+'''';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        If AdoQry_Body.fieldbyname('TmpField').AsInteger = 0 then 
        begin
          ExecuteSql(AdoQry_Tmp,'select ExchRate from InvOutBill where InvBillNo='+QuotedStr(Edt_ShipNo.Text),0)        ;
          SqlText:=' UpDate InvOutBillLine '
                  +' Set '
                  +' InvBillLineNo='''+IntToStr(AdoQry_Body.fieldbyname('InvBillLineNo').AsInteger)+''','
                  +' 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+'''';
          ExecuteSql(AdoQry_Tmp,SqlText,1);
          SqlText:=' Update Sa_SaleOrderLine Set PrepareShipQty='''+AdoQry_Body.fieldbyname('InvBillQty').AsString+''' '
                  +' Where  SloNo='''+AdoQry_Body.fieldbyname('SloNo').AsString+''' '
                  +'   And  SloLineNo='''+IntToStr(AdoQry_Body.fieldbyname('SloLineNo').AsInteger)+'''';
          ExecuteSql(AdoQry_Tmp,SqlText,1);
        end
        else begin
          SqlText:=' Insert InvOutBillLine '
                  +' (InvBillId,InvBillLineNo,SloNo,SloLineNo,ItemCode,InvBillQty,InvBillNoTaxPrice,InvBillNoTaxPriceC, '
                  +' InvBillNoTaxAmount, InvBillNoTaxAmountC, InvBillPrice, InvBillPriceC,'
                  +' InvBillAmount, InvBillAmountC,DiSCountRate,DiSCountAmount,BillLineRemArk,BatchNo)'
                  +'Values('
                  +IntToStr(AdoQry_Head.fieldbyname('InvBillId').AsInteger)+','
                  +''''+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('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_Body.fieldbyname('BatchNo').AsString+''''
                  +')';
          ExecuteSql(AdoQry_Tmp,SqlText,1);
          SqlText:=' Update Sa_SaleOrderLine Set PrepareShipQty='''+AdoQry_Body.fieldbyname('InvBillQty').AsString+''' '
                  +' Where  SloNo='''+AdoQry_Body.fieldbyname('SloNo').AsString+''' '
                  +'   And  SloLineNo='''+IntToStr(AdoQry_Body.fieldbyname('SloLineNo').AsInteger)+'''';
          ExecuteSql(AdoQry_Tmp,SqlText,1);
        end;
        AdoQry_Body.Next;
      end;
      SqlText := 'Delete from InvOutBillLine '
                +' where Convert(varchAr,InvBillId)+'':''+Convert(varchAr,InvBillLineNo) In ('+DeletedInvBillLIne+')';
      ExecuteSql(AdoQry_Tmp,SqlText,1);
    end;
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;
    DispInfo('数据保存成功!',3);
  Except
   on e:exception do
    begin
    DbConnect.RollBackTrans;
    recOrderror(self,AdoQry_tmp,e.message);
//    Edt_ShipNo.Text:='';
    DispInfo('保存数据失败,请重试!',1);
    Abort;
    end;
  end;
  with Frm_Sal_Enter_OtherShipOrderH.AdoQry_Head do
  begin
    If CurrentFormStatus='Add' Then
      Append
    else
      edit;
    fieldbyname('InvBillNo').AsString:=Edt_ShipNo.Text;
    fieldbyname('CustomerCode').AsString:=Edt_CustomerCode.Text;
    fieldbyname('CustomerName').AsString:=Edt_CustomerName.TExt;
    fieldbyname('TotalInvBillNoTaxAmount').AsString:=Edt_TotalNoTaxAmount.Text ;
    fieldbyname('TotalInvBillAmount').AsString:=Edt_TotalTaxAmount.Text ;
    If CurrentFormStatus='Add' Then
    begin
      fieldbyname('Sal_EmployeeCode').AsString:=UserCode;
      fieldbyname('InvBillDate').Asstring:=MEdt_CreateDate.Text;
    end
    else
    begin
    end;

    fieldbyname('InvBillDate').Asstring:=MEdt_CreateDate.Text;
    fieldbyname('DeptCode').AsString:=Edt_SaleDeptCode.Text;
    fieldbyname('DeptName').AsString:=Edt_SaleDeptName.Text ;
  //  fieldbyname('SaleDeptFalg').AsString:=Edt_SaleDeptCode.Text+' '+Lab_SaleDeptName.Caption;

    fieldbyname('SaleType').AsString:=Edt_SaleTypeCode.Text;
    fieldbyname('SaleTypeName').asstring:=edt_SaleTypeName.Text;
    fieldbyname('BillTypeCode').AsString := IIFValue(Cmb_BillType.ItemIndex=0,'0205','0206');
    fieldbyname('SaleEmployeeCode').AsString:=Edt_SaleEmployeeCode.Text;
    fieldbyname('EmployeeName').AsString:= Edt_SaleEmployeeName.Text;
//    fieldbyname('EmployeeName_1').AsString:= Label20.Caption;

   // fieldbyname('SaleEmployeeFalg').AsString:=Edt_SaleEmployeeCode.Text+' '+Lab_SaleEmployeeName.Caption;

    fieldbyname('CurrencyCode').AsString:=Edt_CurrencyCode.Text;
    fieldbyname('CurrencyName').AsString:=Edt_CurrencyName.Text ;
   // fieldbyname('CurrencyFalg').AsString:=Edt_CurrencyCode.Text+' '+Lab_CurrencyName.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('InvBillTaxRate').AsString:=Edt_TaxRate_Percent.Text;
    fieldbyname('ShipModeCode').AsString:=Edt_ShipModeCode.Text;
    fieldbyname('ShipModeName').AsString:=Edt_ShipModeName.Text ;
  //  fieldbyname('ShipModeFalg').AsString:=Edt_ShipModeCode.Text+' '+Lab_ShipModeName.Caption;

    fieldbyname('ShipAddresSCode').AsString:=Edt_ShipAddresSCode.Text;
    fieldbyname('ShipAddressName').AsString:=Edt_ShipAddressName.Text ;
   // fieldbyname('ShipAddressFalg').AsString:=Edt_ShipAddresSCode.Text+' '+Lab_ShipAddressName.Caption;

    fieldbyname('PayTermCode').AsString:=Edt_PayTermCode.Text;
    fieldbyname('SaleTermName').AsString:=Edt_SaleTermName.Text ;
    //fieldbyname('SaleTermFalg').AsString:=Edt_PayTermCode.Text+' '+Lab_SaleTermName.Caption;

    fieldbyname('RemArk').AsString:=Edt_RemArk.Text;
    fieldbyname('RemArk1').AsString := Edt_RemArk1.Text;
    post;
  end;
  inherited;
  Act_InsertLine.Enabled := False;
  Act_DeleteLine.Enabled := False;
end;

procedure TFrm_Sal_Enter_OtherShipOrder.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;

⌨️ 快捷键说明

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