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

📄 ipay.pas

📁 飞恒进销存(超市批发)管理系统V5.1(含源程序) 语言:Delphi 6/7 相关控件:FastReport 2.4以上, Ehlib 3.4以上 1.数据库为fhe2db_V51.da
💻 PAS
字号:
unit IPay;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Unitmb, ImgList, Menus, ComCtrls, ToolWin, Grids, DBGridEh,
  Buttons, StdCtrls, ExtCtrls, FR_Ctrls, Mask, DBCtrls, dbcgrids, DBCtrlsEh;

type
  TIPayForm = class(TmbForm)
    lblStyle: TLabel;
    lblAmount: TLabel;
    edtAmount: TEdit;
    edtChkNo: TEdit;
    cboPayStyle: TComboBox;
    procedure edtEmpButtonClick(Sender: TObject);
    procedure edtStoreButtonClick(Sender: TObject);
    procedure cmdEditClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cmdSaveClick(Sender: TObject);
  private
    { Private declarations }
    nBankId,nPayTypeid:integer;
    nOldBankId,nOldPayTypeid:integer;
    sOldChkNo,sOldPayStyle,sPayStyle:string;
    nOldBillAmt:real;
    procedure InitInfo;override;
    procedure InsertDetail;override;
    procedure UpdateDetail;override;
    procedure InsertMaster(sInvono:string);override;
    procedure UpdateMaster;override;
    procedure ShowMasterSpecial(bAdd:boolean);override;
  public
    { Public declarations }
  end;

var
  IPayForm: TIPayForm;

implementation

uses datamodule1, selPaytype;

{$R *.dfm}

procedure TIPayForm.InitInfo;
begin
  inherited;
  nStoreId:=100;
  nEmployId:=100;
  nBankId:=-1;
  nPayTypeId:=-1;
end;

procedure TIPayForm.InsertDetail;
var
  sSql:string;
  nLeftAmt:real;
begin
  with dataE2 do
  begin
    nLeftAmt:=queryDetail.fieldbyname('Total').ascurrency;
    if queryDetail.fieldbyname('amount').ascurrency <= nLeftAmt then
      nLeftAmt:=queryDetail.fieldbyname('amount').ascurrency;

    sSql:='( :billid, :itemno, :xBillId, :amount, :memo1)';
    adoCmd.commandtext:='insert into '+myTable+'D values '+sSql;
    adoCmd.parameters[0].value:=nBillId;
    adoCmd.parameters[1].value:=queryDetail.fieldbyname('itemno').asinteger;
    adoCmd.parameters[2].value:=queryDetail.fieldbyname('xBillId').asinteger;
    adoCmd.parameters[3].value:=nLeftAmt;//queryDetail.fieldbyname('amount').ascurrency;
    adoCmd.parameters[4].value:=queryDetail.fieldbyname('memo1').asstring;

    adoCmd.execute;
  end;
end;

procedure TIPayForm.UpdateDetail;
var
  nLeftAmt:real;
begin
  with dataE2 do
  begin
    adoCmd.commandtext:='update '+myTable+'D set Amount = :Amount,  memo1= :memo1 where billid= :billid and itemno= :itemno';
    adoCmd.parameters[0].value:=queryDetail.fieldbyname('Amount').ascurrency;
    adoCmd.parameters[1].value:=queryDetail.fieldbyname('memo1').asstring;
    adoCmd.parameters[2].value:=nBillId;
    adoCmd.parameters[3].value:=queryDetail.fieldbyname('itemno').asstring;

    adoCmd.execute;
  end;
end;

procedure TIPayForm.InsertMaster(sInvoNo:string);
begin
  with dataE2 do
    InsertIPay(nBillid,nCusId,nEmployid,nBankId,nPayTypeId,edtBillDate.date,sInvoNo,edtMemo.text,edtChkNo.text,cboPayStyle.text,myTable,edtAmount.text);
end;

procedure TIPayForm.UpdateMaster;
var
  i:integer;
begin
  sMasterMemo:=trim(edtMemo.text);
  sPayStyle:=trim(cboPayStyle.text);

  //dynamic sql sentence
  i:=0;
  with dataE2 do
  begin
    adoCmd.CommandText:='update '+mytable+' set ';

    if  nCusId <> nOldCusId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      if nTableid=3 then
        adoCmd.CommandText :=adoCmd.CommandText +' vendorId= :cusid '
      else
        adoCmd.CommandText :=adoCmd.CommandText +' ClientId= :cusid ';
      adoCmd.Parameters[i].value:=nCusId;
      inc(i);
    end;

    if  nBankId <> nOldBankId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' BankId= :BankId ';
      adoCmd.Parameters[i].value:=nBankId;
      inc(i);
    end;

    if  nPayTypeId <> nOldPayTypeId then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' PayTypeid= :Paytypeid ';
      adoCmd.Parameters[i].value:=nPaytypeId;
      inc(i);
    end;

    if  sOldchkNo <> edtChkNo.text then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' CheckNo= :CheckNo ';
      adoCmd.Parameters[i].value:=edtChkNO.text;
      inc(i);
    end;

    if  (nOldBillAmt <> StrToFloat(edtAmount.text)) and ((cboPayStyle.Text='预付款') or (cboPayStyle.Text='预收款')) then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' BillAmt= :BillAmt ';
      adoCmd.Parameters[i].value:=StrToFloat(edtAmount.text);
      inc(i);
    end;

    if  sMasterMemo <> sOldMasterMemo then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' Memo= :Memo ';
      adoCmd.Parameters[i].value:=sMastermemo;
      inc(i);
    end;

    if  sPayStyle <> sOldPayStyle then
    begin
      if i >0 then adoCmd.CommandText :=adoCmd.CommandText +',';

      adoCmd.CommandText :=adoCmd.CommandText +' PayStyle= :PayStyle ';
      adoCmd.Parameters[i].value:=sPayStyle;
      inc(i);
    end;

    if i>0 then
    begin
      adoCmd.CommandText :=adoCmd.CommandText +' where BillId= :Billid ';
      adoCmd.parameters[i].value:=nBillid;
      adoCmd.Execute ;
    end;
  end; //dataE2
end;

procedure TIPayForm.ShowMasterSpecial(bAdd:boolean);
var
  s,sSql:string;
begin
  with DataE2 do
  if not bAdd then
  begin
    nEmployId:=adoquery1.fieldbyname('EmployId').asinteger;
    nPayTypeId:=adoquery1.fieldbyname('PaytypeId').asinteger;
    nBankId:=adoquery1.fieldbyname('BankId').asinteger;
    sMasterMemo:=trim(adoquery1.fieldbyname('Memo').asstring);

    edtAmount.Text:=trim(adoquery1.fieldbyname('BillAmt').asstring);
    edtMemo.text:=sMastermemo;
    cboPayStyle.Text:=trim(adoquery1.fieldbyname('PayStyle').asstring);
    edtChkNo.Text:=trim(adoquery1.fieldbyname('CheckNo').asstring);

    if nTableid=3 then
    begin
      nCusId:=adoquery1.fieldbyname('VendorId').asinteger;
      sSql:= 'select * from vendor where vendorId= :vendorid'; end
    else begin
      nCusId:=adoquery1.fieldbyname('ClientId').asinteger;
      sSql:= 'select * from client where clientId= :clientd';
    end;

    s:='';
    if OpenTable('select * from bank where bankId= :bankid',nBankid) then
      s:=adoquery1.fieldbyname('name').asstring;

    edtEmp.text:=s;
    adoQuery1.close;

    s:='';
    if OpenTable(sSql,nCusid) then
      s:=adoquery1.fieldbyname('ShortName').asstring;

    edtName.text:=s;

    s:='';
    if OpenTable('select * from Paytype where PaytypeId= :Paytypeid',nPaytypeId) then
      s:=adoquery1.fieldbyname('name').asstring;

    edtStore.text:=s;

    adoQuery1.close;
  end
  else begin  //add emptye record,so clear last infomation
    edtAmount.Text:='';
    if nTableid=3 then
      cboPayStyle.Text:='应付款'
    else
      cboPayStyle.Text:='应收款';
    //edtStore.Text:='';
    //edtEmp.Text:='';
    edtchkNo.Text:='';
    edtMemo.text:='';

    //付款方式
    s:='';
    nPaytypeId:=1;
    if OpenTable('select * from Paytype where PaytypeId= :Paytypeid',nPaytypeId) then
      s:=adoquery1.fieldbyname('name').asstring;

    edtStore.text:=s;

    //银行帐户
    s:='';
    nBankid:=1;
    if OpenTable('select * from bank where bankId= :bankid',nBankid) then
      s:=adoquery1.fieldbyname('name').asstring;

    edtEmp.text:=s;
    adoQuery1.close;

  end;
end;

procedure TIPayForm.edtEmpButtonClick(Sender: TObject);
begin
//  inherited;
  if not cmdSave.Enabled then exit;

  dlgselPayType.Newsql:='select Bankid as id,name from bank ';
  dlgSelpaytype.Top :=self.top+(sender as TComboBox).Top +81;//toolbar1.height+edtInstore.Height+20 ;
  dlgSelpaytype.Left :=self.Left+(sender as TComboBox).left+4 ;
  if dlgselPayType.showmodal=mrok then
  with dataE2 do
  begin
    (sender as TComboBox).Text :=dlgselPayType.xName;
    nBankId:=dlgSelPaytype.xid;
  end;

end;

procedure TIPayForm.edtStoreButtonClick(Sender: TObject);
begin
//  inherited;
  if not cmdSave.Enabled then exit;

  dlgselPayType.Newsql:='select Paytypeid as id,name from paytype ';
  dlgSelpaytype.Top :=self.top+(sender as TComboBox).Top +81;//toolbar1.height+edtInstore.Height+20 ;
  dlgSelpaytype.Left :=self.Left+(sender as TComboBox).left+4 ;
  if dlgselPayType.showmodal=mrok then
  with dataE2 do
  begin
    (sender as TComboBox).Text :=dlgselPayType.xName;
    nPayTypeId:=dlgSelPaytype.xid;
  end;

end;

procedure TIPayForm.cmdEditClick(Sender: TObject);
begin
  inherited;
  nOldBankId:=nBankId;
  nOldPaytypeId:=nPaytypeId;
  sOldChkNo:=edtChkNo.Text;
  sOldPayStyle:=trim(cboPayStyle.Text);
  nOldBillAmt:=StrToFloat(edtAmount.text);
end;

procedure TIPayForm.FormCreate(Sender: TObject);
begin
  inherited;
  if nTableid=13 then
  begin
    LblFormName.Caption :='销售收款';
    caption:=lblFormName.caption;
    lblName.caption:='客  户';
    lblAmount.Caption:='收款金额';
    lblStyle.Caption:='收款类型';
    lblStore.Caption:='收款方式';
    lblEmp.Caption:='收款帐号';

    dbGrid1.Columns[0].title.caption:='销售日期';
    dbGrid1.Columns[1].title.caption:='销售单号';

    cboPaystyle.Items.clear;
    cboPaystyle.Items.add('预收款');
    cboPaystyle.Items.add('应收款');
    cboPaystyle.Items.add('预收冲应收');
  end;

end;

procedure TIPayForm.cmdSaveClick(Sender: TObject);
begin
  if (nPayTypeId< 0 )  then
  begin
    application.MessageBox('请选择收付款类型  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  if (nBankId< 0 )  then
  begin
    application.MessageBox('请选择收付款帐户  ','错误',MB_OK+MB_ICONERROR);
    exit;
  end;

  inherited;
end;

end.

⌨️ 快捷键说明

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