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

📄 usalesettlement.pas

📁 天涯進銷存系統
💻 PAS
字号:
unit uSaleSettlement;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, LBMorphVCLBase, LBMorphButton, StdCtrls, jpeg,
  LBCtrls, LBDBCtrls, LBCurrencyCtrls, LBDBCurrencyCtrls, DBCtrls;

type
  TfrmSaleSettlement = class(TForm)
    Image2: TImage;
    WindowCaption: TLabel;
    SysCloseButton: TLBMorphButton;
    Panel4: TPanel;
    Panel6: TPanel;
    Panel3: TPanel;
    Label10: TLabel;
    Label16: TLabel;
    Label18: TLabel;
    Label19: TLabel;
    Label22: TLabel;
    Shape7: TShape;
    Panel1: TPanel;
    Label25: TLabel;
    Shape8: TShape;
    Panel2: TPanel;
    EnterButton: TLBButton;
    CancelButton: TLBButton;
    Label1: TLabel;
    Label2: TLabel;
    CurrentsumEdit: TLBCurrencyEdit;
    LBComboBox1: TLBComboBox;
    LBEdit1: TLBEdit;
    CurrencyEdit: TLBCurrencyEdit;
    isPrepaySumCheck: TLBCheckBox;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label26: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label6: TLabel;
    Edit1: TEdit;
    procedure Image2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SysCloseButtonClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormShow(Sender: TObject);
    procedure CurrentsumEditExit(Sender: TObject);
    procedure isPrepaySumCheckClick(Sender: TObject);
    procedure CurrentsumEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure CurrencyEditExit(Sender: TObject);
    procedure CurrencyEditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure EnterButtonClick(Sender: TObject);
  private
    procedure GetSum;
  public
    { Public declarations }
  end;

var
  frmSaleSettlement: TfrmSaleSettlement;
  OpposingName, BCode, BDate : string;
  SPaySum, SAlrSum, Sum1, Sum2, Sum3, Sum: Double;

implementation

uses uDataMo, uPublicvar, uConst, Tools, uSaleBill;

{$R *.dfm}

procedure TfrmSaleSettlement.GetSum;
begin
  //可用金额
  //如果使用预付款则加上预付金额
  if isPrepaySumCheck.Checked then
    Sum:=Sum2+CurrentsumEdit.Value
  else
    Sum:=CurrentsumEdit.Value;
  //如果可用金额大于应收款总金额则有余额
  if Sum-Sum1>0 then Sum3:=Sum-Sum1
  else Sum3:=0;
  //可用总金额
  Label3.Caption:=Addradixpoint(FloatToStr(Sum),2);
  //余额
  Label4.Caption:=Addradixpoint(FloatToStr(Sum3),2);
end;

procedure TfrmSaleSettlement.FormShow(Sender: TObject);
var
  s: string;
begin
  s:='select Code, ClientName, PREPAYSUM From ClientInfo where Code='+
     #39+OpposingCode+#39;
  OpenData(s, dmData.sdsPublic);
  if dmData.sdsPublic.IsEmpty then
  begin
    Application.MessageBox(PChar('没有编号为“'+OpposingCode+
                           '”的对方单位,请重新输入。'),Hintinfo, $30);
    Exit;
    Close;
  end;
  OpposingName:=dmData.sdsPublic.Fields[1].AsString;
  Sum1:=StrToFloat(Label1.Caption);
  Sum2:=dmData.sdsPublic.Fields[2].asFloat;
  Label2.Caption:=Addradixpoint(FloatToStr(Sum2), 2);
  Label3.Caption:=Addradixpoint('0', 2);
  Label4.Caption:=Addradixpoint('0', 2);
  LBComboBox1.ItemIndex:=0; 
end;

//八大凶人妙笔


procedure TfrmSaleSettlement.Image2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  SendMessage(Handle, wm_SysCommand ,$F012, 0);
end;

procedure TfrmSaleSettlement.SysCloseButtonClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmSaleSettlement.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if key=27 then Close;
end;

procedure TfrmSaleSettlement.CurrentsumEditExit(Sender: TObject);
begin
  if CurrentsumEdit.Value<0 then
  begin
    Application.MessageBox('收款金额不能小于零。',Hintinfo,$30);
    Edit1.SetFocus;
    CurrentsumEdit.SetFocus;
    Exit;
  end;
  GetSum;
end;

procedure TfrmSaleSettlement.isPrepaySumCheckClick(Sender: TObject);
begin
  GetSum;
end;

procedure TfrmSaleSettlement.CurrentsumEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then  Perform(WM_NEXTDLGCTL,0,0);
end;

procedure TfrmSaleSettlement.CurrencyEditExit(Sender: TObject);
begin
  if (Sum-Sum1>=0) and (CurrencyEdit.Value>0) then
  begin
    Application.MessageBox('不存在让利金额。',Hintinfo,$30);
    CurrencyEdit.Value:=0;
    Exit;
  end;
  if CurrencyEdit.Value>MaxAGIOSUM then
  begin
    Application.MessageBox('让利金额不可超出最大让利金额。',Hintinfo, $30);
    Edit1.SetFocus;
    CurrencyEdit.SetFocus;
    Exit;
  end;
  if (CurrencyEdit.Value>Sum1-Sum) and (CurrencyEdit.Value>0) then
  begin
    Application.MessageBox('让利金额不可大于未收金额。',Hintinfo,$30);
    CurrencyEdit.Value:=Sum1-Sum;
    Edit1.SetFocus;
    CurrencyEdit.SetFocus;
    Exit;
  end;
end;

procedure TfrmSaleSettlement.CurrencyEditKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if key=13 then EnterButtonClick(Sender);
end;

procedure TfrmSaleSettlement.EnterButtonClick(Sender: TObject);
var
  s1, s, BillCode, isPrepaySum, isPaySum: string;
  PaySum: Double;
begin
  Edit1.SetFocus;
  if Sum<=0 then
  begin
    Application.MessageBox('本次收款金额为零,不可保存。',Hintinfo, $30);
    CurrentsumEdit.SetFocus;
    Exit;
  end;
  if Application.MessageBox('确定所输入的付款金额正确吗?', Hintinfo, $24)=idNo then Exit;
  BillCode:=ComDepotCode+'-'+'SK'+'-'+ GetBillID('41', DateToStr(Date));
  //如果有余额
  if Sum3>0 then
  begin
    PaySum:=Sum-Sum3+CurrencyEdit.Value;
    if Application.MessageBox('余额是否转为预收款?',Hintinfo,$24)=idYes then
    begin
      Label5.Caption:='转预收款';
      S1:='1';
    end
    else
    begin
       Label5.Caption:='找零';
       S1:='0';
    end;
  end
  else
  begin
    Label5.Caption:='无';
    PaySum:=Sum+CurrencyEdit.Value;
  end;
  isPaySum:='Float';
  try
  //更新销售单
  with frmSaleBill.BillHandData do
  begin
    ReadOnly:=False;
    Edit;
    FieldByName('ACCEPTSUM').asFloat:=FieldByName('ACCEPTSUM').asFloat+PaySum;
    //如果有折扣金额
    if Sum3>0 then
      FieldByName('AGIOSUM').asFloat:=FieldByName('AGIOSUM').asFloat+Sum3;
    //如果收款金额等于或大于应收金额s
    if (FieldByName('ACCEPTSUM').asFloat+
        FieldByName('AGIOSUM').asFloat)>=
        FieldByName('TOTALSUM').asFloat then
    begin
      FieldByName('ACCEPTSUM').asFloat:=
      FieldByName('TOTALSUM').asFloat-
      FieldByName('AGIOSUM').asFloat;
      FieldByName('ISACCEPT').asString:='1';
      isPaySum:='True';
    end;
    ApplyUpdates(-1);
    ReadOnly:=True;
  end;
  //更新客户资料
  s:='Update ClientInfo Set ARREARAGESUM=ARREARAGESUM-'+FloatToStr(PaySum);
  //如果有使用预收款,则减预收金额
  if isPrepaySumCheck.Checked  then
  begin
    s:=s+',PREPAYSUM=PREPAYSUM-'+FloatToStr(Sum2);
    isPrepaySum:='True';
  end
  else isPrepaySum:='False';
  //如果是转成预收款则转为预收款
  if S1='1' then
     s:=s+',PREPAYSUM=PREPAYSUM+'+FloatToStr(Sum3);
  //未收金额
  s:=s+', PAYMENTSUM=ARREARAGESUM-PREPAYSUM-REIMBURSESUM '+
  'where Code='+#39+OpposingCode+#39;
  with dmData.SQLQuery do
  begin
    Close;
    SQL.Text:=S;
    ExecSQL;
  end;
  //增加销售收款单
  //主表
  s:='Insert into PaymentHand values('+
     #39+BillCode+#39+','+#39+DateToStr(Date)+#39+','+
     #39+OpposingCode+#39+','+#39+OpposingName+#39+','+
     #39+'销售收款'+#39+','+#39+'0'+#39+','+
     FloatToStr(Sum1)+','+FloatToStr(Sum2)+','+
     FloatToStr(CurrentsumEdit.Value)+','+
     #39+Trim(LBComboBox1.Text)+#39+','+#39+Trim(LBEdit1.Text)+#39+','+
     FloatToStr(CurrencyEdit.Value)+','+#39+isPrepaySum+#39+','+
     FloatToStr(Sum)+','+FloatToStr(Sum3)+','+
     #39+Label5.Caption+#39+','+FloatToStr(Sum-Sum3)+','+
     #39+SumSmallTOBig(Sum-Sum3)+#39+','+#39+'1'+#39+','+
     #39+UserName+#39+','+#39+DateTimeToStr(Now)+#39+','+
     'Null'+','+#39+'1'+#39+','+'Null'+','+#39+UserName+#39+','+
     'Null'+','+#39+S1+#39+')';
  with dmData.SQLQuery do
  begin
    Close;
    SQL.Text:=S;
    ExecSQL;
  end;
  //从表
  s:='insert into PaymentBody values('+
     #39+BillCode+#39+',1,'+#39+BCode+#39+','+
     #39+BDate+#39+','+FloatToStr(SPaySum)+','+
     FloatToStr(SAlrSum)+','+FloatToStr(Sum1)+','+
     FloatToStr(Sum-Sum3)+','+#39+isPaySum+#39+')';
  with dmData.SQLQuery do
  begin
    Close;
    SQL.Text:=S;
    ExecSQL;
  end;
  Application.MessageBox('收款保存数据成功。', Hintinfo, $30);
  Close;
  except
    Application.MessageBox('收款保存数据失败。', Errorinfo, $10);
  end;
end;

end.

⌨️ 快捷键说明

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