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

📄 ar_enter_saleinvoice4.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
        If FormStatus='Query' then
          begin
            CurrentFormStatus:='Query';
            With AdoQry_Head do
            begin
              Edt_CustomerCode.Text:=fieldbyname('CustomerCode').AsString;
              Edt_CustomerName.Caption:=fieldbyname('CustomerName').AsString;
              edt_taxactno.Text:=fieldbyname('taxactno').asstring;
              Edt_CreateEmployeeCode.Text:=fieldbyname('CreateEmployeeCode').AsString;
              Edt_CreateEmployeeName.Text := fieldbyname('CreaterName').AsString;
              ExecuteSql(AdoQry_tmp,'select EmployeeName from Employee where EmployeeCode='+QuotedStr(Edt_CreateEmployeeCode.Text),0);
              Edt_CreateEmployeeName.Text := AdoQry_tmp.fieldbyname('EmployeeName').AsString;
              MEdt_CreateDate.Text:=Formatdatetime('yyyy.mm.dd',fieldbyname('BillDate').asdatetime);
              Medt_InAccountDate.Text := FormatDateTime('yyyy.mm.dd',fieldbyname('InAccountDate').AsDateTime);
              Edt_CurrencyCode.Text:=fieldbyname('CurrencyCode').AsString;
              Edt_SaleTermCode.Text:=fieldbyname('SaleTermCode').AsString;
              edt_SaleTypeCode.Text:=fieldbyname('SaleTypeCode').asstring;
              edt_SaleTypeName.Text:=fieldbyname('SaleTypeName').asstring;
              edt_DeptCode.Text:=fieldbyname('SaleDeptCode').asstring;
              edt_DeptName.Text:=fieldbyname('DeptName').asstring;
              edt_SaleEmployeeCode.Text:=fieldbyname('SaleEmployeeCode').asstring;
              edt_SaleEmployeeName.Text:=fieldbyname('SaleEmployeeName').asstring;    

              Edt_RemArk.Text:=fieldbyname('RemArk').AsString;
              Edt_TotalTaxAmount.Text:=FloatToStr(-fieldbyname('TotalTaxAmount').AsFloat);
              Edt_TotalNoTaxAmount.Text := FloatToStr(-fieldbyname('TotalNoTaxAmount').AsFloat);
              Edit1.Text :=fieldbyname('CurrencyName').AsString;
              Edit2.Text:=fieldbyname('CustomerName').AsString;
              Edit3.Text:=fieldbyname('PayTermName').AsString;
              Edt_ExchangeRate.Text:=fieldbyname('ExchangeRate').AsString;
              Edt_TaxRate.Text := fieldbyname('TaxRate').AsString;
              Edt_InvoiceNo.Text:=fieldbyname('InvoiceNo').AsString;

              Lab_CurrencyName.Caption:=fieldbyname('CurrencyName').AsString;
              Lab_SaleTermName.Caption:=fieldbyname('PayTermName').AsString;

              SqlText:=' Select  Sa_SaleInvoiceLine.InvoiceNo,Sa_SaleInvoiceLine.InvBillId, '
                      +'   InvOutBill.InvBillNo as ShipNo,Sa_SaleInvoiceLine.InvBillLineNo as ShipLineNo,   '
                      +'   InvOutBillLine.ItemCode, '
                      +'   InvOutBillLine.InvBillQty as ShipQty , InvOutBillLine.InvBillPrice as TaxPrice, InvOutBillLine.InvBillPriceC as TaxPriceC,'
                      +'   InvOutBillLine.InvBillAmount as TaxAmount, InvOutBillLine.InvBillAmountC as TaxAmountC,InvOutBillLine.InvBillNoTaxPrice as NoTaxPrice, '
                      +'   InvOutBillLine.InvBillNoTaxAmount as  NoTaxAmount,InvOutBillLine.DiSCountRate, '
                      +'   InvOutBillLine.DiSCountAmount , '
                      +'   Item.ItemName,Uom.UomName '
                      +'   From Sa_SaleInvoiceLine '
                      +'    Join InvOutBillLine on Sa_SaleInvoiceLine.InvBillId=InvOutBillLine.InvBillId '
                      +'                   and Sa_SaleInvoiceLine.InvBillLineNo=InvOutBillLine.InvBillLineNo '
                      +'    Join InvOutBill on InvOutBillLine.InvBillId = InvOutBill.InvBillId '
                      +'   left Join  Item '
                      +'     On InvOutBillLine.ItemCode = Item.ItemCode '
                      +'   left Join Uom '
                      +'     On Item.UomCode=Uom.UomCode '
                          +'     where Sa_SaleInvoiceLine.InvoiceNo= '''+fieldbyname('InvoiceNo').AsString+''' ' ;

             AdoQry_Body.Close;
             AdoQry_Body.SQL.Text:=SqlText;
             AdoQry_Body.Open;
           end ;
      end;
    end;
  end;
end;

procedure TFrm_Ar_Enter_SaleInvoice4.InitControls;
begin
  If Status<>'Add' then
  begin
    CurrentFormStatus:='PArtEdit';
    SetFocus_Control:=Edt_CustomerCode;
  end
  Else
  begin
    CurrentFormStatus:='Add';
  end;
  If Status='Query' Then
  begin
    Caption:='销售开票明细';
    Pnl_Title.Caption:='销售开票明细';
  end;
  inherited;
  act_Modify.Enabled:=False;
  act_insertline.Enabled:=False;
  act_Deleteline.Enabled:=False;
  edt_ExchangeRate.Enabled:=False;
  Edt_TaxRate.Enabled := False;
  edt_CurrencyCode.Enabled:=False;
  Edt_CustomerCode.Enabled := False;
  Edt_TaxActNo.Enabled := False;
  Edt_SaletermCode.Enabled := False;
  Edt_TotalTaxAmount.Enabled := False;
  Edt_TotalNoTaxAmount.Enabled := False;
//  Edt_TotalTax.Enabled := False;
  Edt_SaleTypeCode.Enabled := False;
  Edt_DeptCode.Enabled := False;
  Edt_SaleEmployeeCode.Enabled := False;
  Edt_CreateEmployeeCode.Enabled := False;
  Edit1.Enabled := False;
  Edit2.Enabled := False;
  Edit3.Enabled := False;
  Edt_SaleTypeName.Enabled := False;
  Edt_DeptName.Enabled := False;
  Edt_SaleEmployeeName.Enabled :=False;
  Edt_CreateEmployeeName.Enabled :=False;

end;

procedure TFrm_Ar_Enter_SaleInvoice4.Edt_SaleTermCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
   If key=120 Then
  CommOnHint(Sender,AdoQry_Tmp,'PayTermName','付款条款名称','PayTermCode',
             '付款条款代号',' PayTerm ');
end;

procedure TFrm_Ar_Enter_SaleInvoice4.Edt_SaleTermCodeExit(Sender: TObject);
begin
  inherited;
  If Trim(Edt_SaleTermCode.text)='' then
  begin
   exit;
  end
  else
  begin
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text:=' Select * from PayTerm where PayTermCode='''+Trim(Edt_SaleTermCode.text)+''' ';
    AdoQry_Tmp.Open;
    if AdoQry_Tmp.Eof then
    begin
      DispInfo('付款条款输入错误!',3);
      Edt_SaleTermCode.SetFocus;
      Abort;
    end;
  end;
  Edit3.Text :=AdoQry_tmp.fieldbyname('PayTermName').asstring;
end;

procedure TFrm_Ar_Enter_SaleInvoice4.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
     TotalNoTaxAmount := TotalNoTaxAmount + AdoQry_Body.fieldbyname('NoTaxAmount').AsFloat;
     TotalTaxAmount:= TotalTaxAmount +AdoQry_Body.fieldbyname('TaxAmount').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_Ar_Enter_SaleInvoice4.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
  if Currentstatus='Add' then
  begin
    AnswerStatus:='Add';
    EnableControls:=' MEdt_CreateDate,MEdt_InAccountDate, Edt_SaleDeptCode, Edt_SaleType,'
                   +' Edt_SaleEmployeeCode,  Edt_TaxRate_Percent,'
                   +' Edt_ShipModeCode, Edt_ShipAddresSCode, '
                   +' Edt_RemArk,Edt_InvoiceNo,';
  end
  Else If Pos('Edit',CurrentStatus)>0 Then
  begin
    AnswerStatus:='PArtEdit';
    EnableControls:=' MEdt_CreateDate,MEdt_InAccountDate,'
                   +'   Edt_ExchangeRate,edt_taxactno,'
                   +'  Edt_SaleTermCode,Edt_CustomerBank,Edt_CustomerBankActNo, '
                   +' Edt_RemArk,';
  end;

end;

procedure TFrm_Ar_Enter_SaleInvoice4.Act_DeleteLineExecute(Sender: TObject);
var
  BookMArk:String;
begin
  inherited;
{ 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;
    While Not AdoQry_Body.Eof Do
    begin
      AdoQry_Body.Edit;
      AdoQry_Body.fieldbyname('ShipLineNo').AsInteger:=AdoQry_Body.RecNo;
      AdoQry_Body.Post;
      AdoQry_Body.Next;
    end;
    AdoQry_Body.BookmArk:=BookMArk;
  end;}
end;

procedure TFrm_Ar_Enter_SaleInvoice4.Act_PreviewExecute(Sender: TObject);
begin
//  inherited;
{  if  Act_Save.Enabled = True then
  begin
    DispInfo('没有保存数据,不能预览!',1);
    Abort;
  end;
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能预览!',1);
    Abort;
  end;
  Frm_Sal_Enter_ShipOrder_P:=TFrm_Sal_Enter_ShipOrder_P.Create(Application);
  Frm_Sal_Enter_ShipOrder_P.SetDBConnect(DbConnect);
  Frm_Sal_Enter_ShipOrder_P.SetSysParam(UserCode,ModuleCode,MenuId,DateTimeToStr(Now));
  Frm_Sal_Enter_ShipOrder_P.GetHeadData(AdoQry_Body,Trim(Edt_ShipNo.Text),'Preview');
  Frm_Sal_Enter_ShipOrder_P:=Nil;}
end;

procedure TFrm_Ar_Enter_SaleInvoice4.Act_PrintExecute(Sender: TObject);
begin
 // inherited;
{ if  Act_Save.Enabled = True then
  begin
    DispInfo('没有保存数据,不能打印!',1);
    Abort;
  end;
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能打印!',1);
    Abort;
  end;
  Frm_Sal_Enter_ShipOrder_P:=TFrm_Sal_Enter_ShipOrder_P.Create(Application);
  Frm_Sal_Enter_ShipOrder_P.SetDBConnect(DbConnect);
  Frm_Sal_Enter_ShipOrder_P.SetSysParam(UserCode,ModuleCode,MenuId,DateTimeToStr(Now));
  Frm_Sal_Enter_ShipOrder_P.GetHeadData(AdoQry_Body,Trim(Edt_ShipNo.Text),'Print');
  Frm_Sal_Enter_ShipOrder_P:=Nil;}
end;

procedure TFrm_Ar_Enter_SaleInvoice4.Act_NewExecute(Sender: TObject);
begin
{  if Frm_Sal_Enter_ShipOrder_C1<>nil then
    Frm_Sal_Enter_ShipOrder_C1:=TFrm_Sal_Enter_ShipOrder_C1.Create(Application);
    Frm_Sal_Enter_ShipOrder_C1.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
    Frm_Sal_Enter_ShipOrder_C1.InitForm(DbConnect,False);}

  inherited;

end;

procedure TFrm_Ar_Enter_SaleInvoice4.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Frm_Ar_Enter_SaleInvoice4:=nil;
end;

procedure TFrm_Ar_Enter_SaleInvoice4.SaveData;
var
  SqlText:String;
  I:integer;
begin
  inherited;
  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('ShipQty').AsFloat))>0 Then
    begin
      DispInfo('第'+IntToStr(I)+'行数据的退货量大于0,不能保存!',3);
      Abort;
    end;
    AdoQry_Body.Next;
     I:=I+1;
  end;
  Application.ProcessMessages;
  DbConnect.beginTrans;
  Try
    AdoQry_Body.First;
    If CurrentFormStatus='Add' Then
    begin
      if Edt_InvoiceNo.Text='' then
      abort;
      Application.ProcessMessages;
            SqlText:='Insert Sa_SaleInvoice '
              +' (InvoiceNo,InvoiceType,BillType,OrderType,SaleDeptCode,SaleEmployeeCode, '
              +'  SaleTypeCode,CreateDate,BillDate,InAccountDate,CreateEmployeeCode,CustomerCode,Bank,'
              +'  BankActNo,TaxActNo,CurrencyCode,ExchangeRate,TaxRate,'
              +'  SaleTermCode,TotalTaxAmount,TotalTaxAmountC,TotalNoTaxAmount, '
              +'  TotalNoTaxAmountC,TotalTax,TotalTaxC,CancelAmount,CancelAmountC,editdate,edItEmployeeCode,RemArk)'
              +'  Values('
              +''''+Trim(Edt_InvoiceNo.Text)+''','
              +'1,0,1, '
              +IIfString(Trim(edt_DeptCode.text)='','null',quotedstr(Trim(edt_DeptCode.text)))+','
              +IIfString(Trim(edt_SaleEmployeeCode.text)='','null',quotedstr(Trim(edt_SaleEmployeeCode.text)))+','
              +IIfString(Trim(edt_SaleTypeCode.text)='','null',quotedstr(Trim(edt_SaleTypeCode.text)))+','
              +'GetDate(),'
              +''''+Trim(MEdt_CreateDate.Text)+''','
              +QuotedStr(MEdt_InAccountDate.Text)+','
              +''''+Trim(Edt_CreateEmployeeCode.Text)+''','
              +''''+Trim(Edt_CustomerCode.Text)+''','
              +''''+Trim(Edt_CustomerBank.Text)+''','
              +''''+Trim(Edt_CustomerBankActNo.Text)+''','
              +QuotedStr(Edt_TaxActNo.Text)+','
              +''''+Trim(Edt_CurrencyCode.Text)+''','
              +''''+Trim(Edt_ExchangeRate.Text)+''','
              +Edt_TaxRate.Text+','
              +IIfString(Trim(edt_SaletermCode.text)='','null',quotedstr(Trim(edt_SaletermCode.text)))+','
              +'-('+Trim(Edt_TotalTaxAmount.Text)+'),'
              +FormatFloat('####0.##',-(StrToFloat(Edt_ExchangeRate.Text)*StrToFloat(Edt_TotalTaxAmount.Text)))+','
              +'-('+Edt_TotalNoTaxAmount.Text+'),'
              +FormatFloat('####0.##',-(StrToFloat(Edt_ExchangeRate.Text)*StrToFloat(Edt_TotalNoTaxAmount.Text)))+','
              +FormatFloat('####0.##',-(StrToFloat(Edt_TotalTaxAmount.Text)-StrToFloat(Edt_TotalNoTaxAmount.Text)))+','
              +FormatFloat('####0.##',-(StrToFloat(Edt_ExchangeRate.TExt)*(StrToFloat(Edt_TotalTaxAmount.Text)-StrToFloat(Edt_TotalNoTaxAmount.Text) )  ))+','
              +'0,'
              +'0,'
              +quotedstr(GetServerDateTime(dbconnect))+','
              +quotedstr(userCode)+','
              +''''+Trim(Edt_RemArk.Text)+''')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.ExecSQL;
      saveSalInvoiceHistory(dbconnect,Trim(Edt_InvoiceNo.Text),userCode,0);
    //  SaveSa_SaleOrderHistory(dbconnect,Trim(edt_SloNo.text),userCode,0);
      Sqltext:='Update customer with(Rowlock)'
              +'   set InvoiceSumTotal=IsNull(InvoiceSumTotal,0)+'+Edt_TotalTaxAmount.text
              +' Where CustomerCode='+QuotedStr(Edt_CustomerCode.text);
      ExecuteSql(AdoQry_Tmp,sqltext,1)              ;
      AdoQry_Body.First;
      While Not AdoQry_Body.Eof Do
      begin
        SqlText:='Insert Sa_SaleInvoiceLine '
                +' (InvoiceNo,InvBillId,InvBillLineNo,RemArk) '
                +' Values('
                +''''+Trim(Edt_InvoiceNo.Text)+''','

⌨️ 快捷键说明

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