505 lines
13 KiB
ObjectPascal
505 lines
13 KiB
ObjectPascal
unit U_FDINVOICE_Sub;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
Dialogs, ComCtrls, ToolWin, cxStyles, cxCustomData, cxGraphics, cxFilter,
|
||
cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses,
|
||
cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
|
||
cxGridDBTableView, cxGrid, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB,
|
||
DBClient, ExtCtrls, StdCtrls, BtnEdit, cxButtonEdit, cxTextEdit,
|
||
cxDropDownEdit, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;
|
||
|
||
type
|
||
TFrmInvoice_Sub = class(TForm)
|
||
DataSource1: TDataSource;
|
||
FP_Sub: TClientDataSet;
|
||
cxGridPopupMenu1: TcxGridPopupMenu;
|
||
ToolBar1: TToolBar;
|
||
TSave: TToolButton;
|
||
TBClose: TToolButton;
|
||
ToolBar2: TToolBar;
|
||
TADD: TToolButton;
|
||
TDEl: TToolButton;
|
||
Panel1: TPanel;
|
||
cxGrid1: TcxGrid;
|
||
Tv1: TcxGridDBTableView;
|
||
v1P_CodeName: TcxGridDBColumn;
|
||
v1P_Spec: TcxGridDBColumn;
|
||
v1Qty: TcxGridDBColumn;
|
||
v1Price: TcxGridDBColumn;
|
||
v1QtyUnit: TcxGridDBColumn;
|
||
v1Money: TcxGridDBColumn;
|
||
v1note: TcxGridDBColumn;
|
||
cxGridLevel1: TcxGridLevel;
|
||
Label1: TLabel;
|
||
InvoiceNo: TEdit;
|
||
Label2: TLabel;
|
||
Label3: TLabel;
|
||
InvoiceDate: TDateTimePicker;
|
||
Note: TMemo;
|
||
InvoiceType: TBtnEditA;
|
||
ToFactoryName: TBtnEditA;
|
||
FactoryName: TBtnEditA;
|
||
Label4: TLabel;
|
||
Label5: TLabel;
|
||
Label6: TLabel;
|
||
Label7: TLabel;
|
||
Filler: TEdit;
|
||
ADOQueryTmp: TADOQuery;
|
||
ADOQueryCmd: TADOQuery;
|
||
Label8: TLabel;
|
||
SYRName: TBtnEditA;
|
||
v1Column1: TcxGridDBColumn;
|
||
v1Column2: TcxGridDBColumn;
|
||
v1Column3: TcxGridDBColumn;
|
||
v1Column4: TcxGridDBColumn;
|
||
v1Column5: TcxGridDBColumn;
|
||
Tv1Column1: TcxGridDBColumn;
|
||
Tv1Column2: TcxGridDBColumn;
|
||
procedure TBCloseClick(Sender: TObject);
|
||
procedure FormShow(Sender: TObject);
|
||
procedure ToFactoryNameBtnClick(Sender: TObject);
|
||
procedure TSaveClick(Sender: TObject);
|
||
procedure FactoryNameBtnClick(Sender: TObject);
|
||
procedure v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure InvoiceTypeBtnClick(Sender: TObject);
|
||
procedure v1P_SpecPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
procedure TADDClick(Sender: TObject);
|
||
procedure TDElClick(Sender: TObject);
|
||
procedure v1QtyPropertiesEditValueChanged(Sender: TObject);
|
||
procedure SYRNameBtnClick(Sender: TObject);
|
||
private
|
||
procedure initGrid();
|
||
procedure SaveDate();
|
||
{ Private declarations }
|
||
public
|
||
FInvoiceNO: string;
|
||
fInvoiceFlag: string;
|
||
{ Public declarations }
|
||
end;
|
||
|
||
var
|
||
FrmInvoice_Sub: TFrmInvoice_Sub;
|
||
|
||
implementation
|
||
|
||
uses
|
||
U_Fun10, U_ZDYHelp, U_ZdyAttachment, U_dataLink, U_ZdyAttachGYS, U_CPManageSel;
|
||
{$R *.dfm}
|
||
|
||
procedure TFrmInvoice_Sub.SaveDate();
|
||
var
|
||
FInvoiceID, FInvoiceNo: string;
|
||
begin
|
||
ADOQueryCmd.Connection.BeginTrans;
|
||
try
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.add('select * from FD_Invoice where InvoiceNo=''' + trim(InvoiceNo.Text) + '''');
|
||
open;
|
||
if isempty then
|
||
begin
|
||
append;
|
||
fieldbyname('filltime').AsDateTime := SGetServerDate(ADOQueryTmp);
|
||
if GetLSNo(ADOQueryTmp, FInvoiceNo, 'FP', 'FD_Invoice', 4, 1) = False then
|
||
begin
|
||
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
InvoiceNo.Text := FInvoiceNo;
|
||
end
|
||
else
|
||
edit;
|
||
SSetsaveSqlnew(ADOQueryCmd, 'FD_Invoice', panel1, 0);
|
||
fieldbyname('Invoiceflag').Value := strtoint(FInvoiceflag);
|
||
fieldbyname('chkstatus').AsString := '0';
|
||
post;
|
||
end;
|
||
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.add('delete from FD_InvoiceSub where InvoiceNo=''' + trim(InvoiceNo.Text) + ''' ');
|
||
execsql;
|
||
end;
|
||
with FP_Sub do
|
||
begin
|
||
first;
|
||
while not eof do
|
||
begin
|
||
if fieldbyname('invoiceID').AsString = '' then
|
||
begin
|
||
if GetLSNo(ADOQueryTmp, FInvoiceID, 'FP', 'FD_InvoiceSub', 4, 1) = False then
|
||
begin
|
||
Application.MessageBox('ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', 0);
|
||
Exit;
|
||
end;
|
||
end
|
||
else
|
||
FInvoiceID := FP_Sub.fieldbyname('invoiceID').AsString;
|
||
with ADOQueryCmd do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.add('select * from FD_InvoiceSub where InvoiceNo=''' + trim(InvoiceNo.Text) + ''' ');
|
||
sql.add('and InvoiceID=''' + trim(FInvoiceID) + '''');
|
||
open;
|
||
end;
|
||
if ADOQueryCmd.IsEmpty then
|
||
begin
|
||
ADOQueryCmd.append;
|
||
end
|
||
else
|
||
begin
|
||
ADOQueryCmd.edit;
|
||
end;
|
||
ADOQueryCmd.fieldbyname('InvoiceNo').Value := trim(InvoiceNo.Text);
|
||
ADOQueryCmd.fieldbyname('InvoiceID').Value := FInvoiceID;
|
||
SSetSaveDataCDSNew(ADOQueryCmd, Tv1, FP_Sub, 'FD_InvoiceSub', 0);
|
||
ADOQueryCmd.fieldbyname('Qty').Value := FP_Sub.fieldbyname('Qty').AsFloat;
|
||
ADOQueryCmd.fieldbyname('Price').Value := FP_Sub.fieldbyname('Price').AsFloat;
|
||
ADOQueryCmd.fieldbyname('Money').Value := FP_Sub.fieldbyname('Money').AsFloat;
|
||
ADOQueryCmd.fieldbyname('tax').Value := FP_Sub.fieldbyname('tax').AsFloat;
|
||
ADOQueryCmd.fieldbyname('TaxMoney').Value := FP_Sub.fieldbyname('TaxMoney').AsFloat;
|
||
ADOQueryCmd.Post;
|
||
next;
|
||
end;
|
||
end;
|
||
ADOQueryCmd.Connection.CommitTrans;
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>', '<27><>ʾ');
|
||
Modalresult := 1;
|
||
except
|
||
ADOQueryCmd.Connection.RollbackTrans;
|
||
application.MessageBox('<27><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>', '<27><>ʾ', MB_ICONERROR);
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.initGrid();
|
||
begin
|
||
with ADOQueryTmp do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('select * from FD_Invoice where InvoiceNo=''' + trim(FInvoiceNo) + '''');
|
||
open;
|
||
end;
|
||
if ADOQueryTmp.isempty = False then
|
||
begin
|
||
SCSHDataNew(ADOQueryTmp, Panel1, 0);
|
||
end
|
||
else
|
||
begin
|
||
Filler.Text := trim(DName);
|
||
InvoiceDate.DateTime := SGetServerDate(ADOQueryCmd);
|
||
end;
|
||
with ADOQueryTmp do
|
||
begin
|
||
close;
|
||
sql.Clear;
|
||
sql.Add('select *,shuie=taxMoney-Money from FD_InvoiceSub where InvoiceNo=''' + trim(FInvoiceNo) + '''');
|
||
open;
|
||
end;
|
||
SCreateCDS20(ADOQueryTmp, FP_Sub);
|
||
SInitCDSData20(ADOQueryTmp, FP_Sub);
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.TBCloseClick(Sender: TObject);
|
||
begin
|
||
WriteCxGrid('<27><>Ʊ¼<C6B1><C2BC>', Tv1, '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||
Close;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.FormShow(Sender: TObject);
|
||
begin
|
||
ReadCxGrid('<27><>Ʊ¼<C6B1><C2BC>', Tv1, '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>');
|
||
initGrid();
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.ToFactoryNameBtnClick(Sender: TObject);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'YFFtySYRName';
|
||
flagname := '<27>Է<EFBFBD>̧ͷ';
|
||
if ShowModal = 1 then
|
||
begin
|
||
ToFactoryName.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.TSaveClick(Sender: TObject);
|
||
begin
|
||
|
||
// if trim(InvoiceNo.Text) = '' then
|
||
// begin
|
||
// application.MessageBox('<27><>Ʊ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>Ϊ<EFBFBD><CEAA>', '<27><>ʾ');
|
||
// exit;
|
||
// end;
|
||
|
||
if trim(FactoryName.Text) = '' then
|
||
begin
|
||
application.MessageBox('<27><>Ʊ<EFBFBD><C6B1>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>', '<27><>ʾ');
|
||
exit;
|
||
end;
|
||
if trim(FInvoiceNo) = '' then
|
||
begin
|
||
with ADOQueryTmp do
|
||
begin
|
||
close;
|
||
sql.clear;
|
||
sql.add('select * from FD_Invoice where InvoiceNo=''' + trim(InvoiceNo.Text) + ''' ');
|
||
open;
|
||
end;
|
||
if ADOQueryTmp.IsEmpty = False then
|
||
begin
|
||
application.MessageBox('<27><>Ʊ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD>ظ<EFBFBD>', '<27><>ʾ');
|
||
exit;
|
||
end;
|
||
end;
|
||
SaveDate();
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.FactoryNameBtnClick(Sender: TObject);
|
||
begin
|
||
if fInvoiceflag = '0' then
|
||
begin
|
||
try
|
||
frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
|
||
with frmZdyAttachGYS do
|
||
begin
|
||
if ShowModal = 1 then
|
||
begin
|
||
FactoryName.Text := Trim(CDS_HZ.fieldbyname('Name').AsString);
|
||
ToFactoryName.Text := Trim(CDS_HZ.fieldbyname('Name').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZdyAttachGYS.Free;
|
||
end;
|
||
end
|
||
else
|
||
begin
|
||
try
|
||
frmZdyAttachment := TfrmZdyAttachment.Create(Application);
|
||
with frmZdyAttachment do
|
||
begin
|
||
if ShowModal = 1 then
|
||
begin
|
||
FactoryName.Text := Trim(CDS_HZ.fieldbyname('Name').AsString);
|
||
ToFactoryName.Text := Trim(CDS_HZ.fieldbyname('Name').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZdyAttachment.Free;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.v1P_CodeNamePropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'MPRTCodeName';
|
||
flagname := '<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
||
if ShowModal = 1 then
|
||
begin
|
||
Self.FP_Sub.Edit;
|
||
Self.FP_Sub.FieldByName('P_CodeName').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
||
Self.FP_Sub.FieldByName('P_Code').Value := Trim(ClientDataSet1.fieldbyname('ZDYNo').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
//self.tv1.Controller.EditingController.ShowEdit();
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.InvoiceTypeBtnClick(Sender: TObject);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'InvoiceType';
|
||
flagname := '<27><>Ʊ<EFBFBD><C6B1><EFBFBD><EFBFBD>';
|
||
if ShowModal = 1 then
|
||
begin
|
||
InvoiceType.Text := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.v1P_SpecPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'P_Spec';
|
||
flagname := '<27><>Ʒ<EFBFBD><C6B7><EFBFBD><EFBFBD>';
|
||
if ShowModal = 1 then
|
||
begin
|
||
Self.FP_Sub.Edit;
|
||
Self.FP_Sub.FieldByName('P_Spec').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.v1QtyUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'QtyUnit';
|
||
flagname := '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ';
|
||
if ShowModal = 1 then
|
||
begin
|
||
Self.FP_Sub.Edit;
|
||
Self.FP_Sub.FieldByName('QtyUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.v1PriceUnitPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'PriceUnit';
|
||
flagname := '<27><><EFBFBD><EFBFBD>';
|
||
if ShowModal = 1 then
|
||
begin
|
||
Self.FP_Sub.Edit;
|
||
Self.FP_Sub.FieldByName('PriceUnit').Value := Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.TADDClick(Sender: TObject);
|
||
begin
|
||
FP_Sub.Append;
|
||
FP_Sub.FieldByName('QtyUnit').Value := 'Kg';
|
||
FP_Sub.FieldByName('priceUnit').Value := 'RMB';
|
||
FP_Sub.FieldByName('tax').Value := 13;
|
||
FP_Sub.FieldByName('FPDate').Value := Now;
|
||
FP_Sub.Post;
|
||
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.TDElClick(Sender: TObject);
|
||
begin
|
||
if FP_Sub.IsEmpty then
|
||
exit;
|
||
if application.MessageBox('ȷ<><C8B7>Ҫɾ<D2AA><C9BE><EFBFBD><EFBFBD>', '<27><>ʾ', 1) = 2 then
|
||
exit;
|
||
with ADOQueryTmp do
|
||
begin
|
||
close;
|
||
sql.clear;
|
||
sql.add('delete from FD_Invoicesub where InvoiceID=''' + trim(FP_Sub.fieldbyname('InvoiceID').asstring) + ''' ');
|
||
execsql;
|
||
end;
|
||
FP_Sub.delete;
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.v1QtyPropertiesEditValueChanged(Sender: TObject);
|
||
var
|
||
mvalue, FFieldName: string;
|
||
FQty, FPrice, FMoney, Ftax, FtaxMoney: double;
|
||
begin
|
||
FFieldName := Trim(Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName);
|
||
mvalue := TcxTextEdit(Sender).EditingText;
|
||
if Trim(mvalue) = '' then
|
||
begin
|
||
mvalue := '0';
|
||
end;
|
||
with FP_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName(FFieldName).Value := Trim(mvalue);
|
||
Post;
|
||
FQty := FieldbyName('Qty').AsFloat;
|
||
FtaxMoney := FieldbyName('taxMoney').AsFloat;
|
||
Ftax := FieldbyName('tax').AsFloat;
|
||
end;
|
||
if FQty <> 0 then
|
||
begin
|
||
|
||
FMoney := strtofloat(format('%.2f', [FtaxMoney / (1 + Ftax / 100)]));
|
||
FPrice := strtofloat(format('%.2f', [FMoney / FQty]));
|
||
end
|
||
else
|
||
begin
|
||
FPrice := 0;
|
||
FMoney := strtofloat(format('%.2f', [FtaxMoney / (1 + Ftax / 100)]));
|
||
end;
|
||
|
||
with FP_Sub do
|
||
begin
|
||
Edit;
|
||
FieldByName('Price').Value := FPrice;
|
||
FieldByName('Money').Value := FMoney;
|
||
FieldByName('shuie').Value := FtaxMoney - FMoney;
|
||
Post;
|
||
end;
|
||
tv1.Controller.EditingController.ShowEdit();
|
||
|
||
end;
|
||
|
||
procedure TFrmInvoice_Sub.SYRNameBtnClick(Sender: TObject);
|
||
begin
|
||
try
|
||
frmZDYHelp := TfrmZDYHelp.Create(Application);
|
||
with frmZDYHelp do
|
||
begin
|
||
flag := 'SYRName';
|
||
flagname := '<27><>˾̧ͷ';
|
||
if Trim(flag) = 'SYRName' then
|
||
begin
|
||
flag := 'OrdDefStr2';
|
||
V1Name.Caption := '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||
V1Note.Caption := 'Ӣ<><D3A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>';
|
||
fnote := True;
|
||
end;
|
||
if ShowModal = 1 then
|
||
begin
|
||
SYRName.Text := Trim(ClientDataSet1.fieldbyname('ZdyName').AsString);
|
||
end;
|
||
end;
|
||
finally
|
||
frmZDYHelp.Free;
|
||
end;
|
||
end;
|
||
|
||
end.
|
||
|