📄 sledsalebgtp.pas
字号:
unit SLEdSaleBGTP;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, BaseVoucherEdit, Menus, ActnList, DB, ComCtrls, StdCtrls, Mask,
DBCtrls, ExtCtrls, ToolWin, Grids, DBGrids, QLDBGrid, ADODB, GEdit,
QLDBLkp;
type
TSLEdSaleBGTPForm = class(TBaseVoucherEditForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ClientName: TADODataSet;
EmployeeName: TADODataSet;
GoodName: TADODataSet;
Label5: TLabel;
PackUnit: TADODataSet;
dsPackUnit: TDataSource;
DSClientName: TDataSource;
DSEmployeeName: TDataSource;
ClientQLDBLookup: TQLDBLookupComboBox;
LookupEmployee: TQLDBLookupComboBox;
Label6: TLabel;
Label7: TLabel;
LookupPackUint: TQLDBLookupComboBox;
TempAds: TADODataSet;
adsMaster: TADODataSet;
adsDetail: TADODataSet;
adsDetailID: TAutoIncField;
adsDetailMasterID: TIntegerField;
adsDetailGoodsID: TIntegerField;
adsDetailQuantity: TBCDField;
adsDetailQuantityPcs: TBCDField;
adsDetailPackUnitID: TIntegerField;
adsDetailPriceBase: TBCDField;
adsDetailAmount: TBCDField;
adsDetailDiscount: TBCDField;
adsDetailGoalQuantity: TBCDField;
adsDetailSundryFee: TBCDField;
adsDetailGoalUnitID: TIntegerField;
adsMasterID: TAutoIncField;
adsMasterCreateDate: TDateTimeField;
adsMasterCreateUserID: TIntegerField;
adsMasterRecordState: TStringField;
adsMasterDate: TDateTimeField;
adsMasterCode: TStringField;
adsMasterClientID: TIntegerField;
adsMasterBillMode: TStringField;
adsMasterPeriodID: TIntegerField;
adsMasterClearDate: TDateTimeField;
adsMasterMemo: TStringField;
adsMasterSundryFee: TBCDField;
Label8: TLabel;
adsMasterClientName: TStringField;
adsDetailPackUnit: TStringField;
DiscountMode: TAction;
adsMasterEmployeeID: TIntegerField;
adsMasterApportion: TStringField;
adsMasterDeliver: TStringField;
adsMasterOriginID: TIntegerField;
adsMasterOriginTable: TStringField;
adsMasterBillAffix: TBytesField;
adsDetailMemo: TStringField;
adsMasterBrief: TStringField;
BriefComboBox: TDBComboBox;
Label9: TLabel;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
Label10: TLabel;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
Label4: TLabel;
DBEdit5: TDBEdit;
GEdit1: TGEdit;
adsDetailTaxAmount: TBCDField;
adsDetailGoodsSpec: TStringField;
adsGoodsSpec: TADODataSet;
dsGoodsSpec: TDataSource;
adsMasterEmployee: TStringField;
GoalUnit: TADODataSet;
dsGoalUnit: TDataSource;
adsDetailGoalUnit: TStringField;
adsMasterModeDC: TIntegerField;
adsMasterModeC: TIntegerField;
adsMasterWarehouseID: TIntegerField;
adsDetailGoodsName: TStringField;
TpPackUnit: TADOQuery;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure adsDetailPackUnitIDChange(Sender: TField);
procedure adsDetailGoodsIDChange(Sender: TField);
procedure SaveActionExecute(Sender: TObject);
procedure ClientQLDBLookupEnter(Sender: TObject);
procedure ClientQLDBLookupExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure FormDeactivate(Sender: TObject);
procedure adsDetailPriceBaseChange(Sender: TField);
procedure adsDetailGoalQuantityChange(Sender: TField);
private
{ Private declarations }
public
SLPubQuerrySql,SLPubQuerryCaption:string;
{ Public declarations }
procedure Open(VoucherID: Integer); override;
procedure New; override;
end;
var
SLEdSaleBGTPForm: TSLEdSaleBGTPForm;
implementation
uses CommonDM, WSUtils, WSSecurity;
{$R *.dfm}
procedure TSLEdSaleBGTPForm.New;
begin
inherited;
adsMaster.FieldByName('Date').AsDateTime:=Date;
adsMaster.FieldByName('Code').AsString:=GetMaxCode('Code','SLSaleMaster',number);
adsMaster.FieldByName('CreateUserID').AsInteger :=Guarder.UserID;
// adsMaster.FieldByName('BIllMode').ReadOnly :=False;
adsMaster.FieldByName('BillMode').AsString :='销售退货';
// adsMaster.FieldByName('BIllMode').ReadOnly :=True;
adsMaster.FieldByName('ModeDC').AsInteger :=-1;
adsMaster.FieldByName('ModeC').AsInteger :=1;
adsMaster.FieldByName('Deliver').AsString :='--';
adsMaster.FieldByName('Apportion').AsString :='--';
adsMaster.FieldByName('OriginTable').AsString:='SLSaleMaster';
end;
procedure TSLEdSaleBGTPForm.Open(VoucherID: Integer);
begin
inherited Open(VoucherID);
end;
procedure TSLEdSaleBGTPForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
adsMaster.Close;
adsDetail.Close;
ClientName.Close;
EmployeeName.Close;
GoodName.Close;
PackUnit.Close;
adsGoodsSpec.Close;
end;
procedure TSLEdSaleBGTPForm.FormCreate(Sender: TObject);
var GoodsSpecStr:string;
begin
inherited;
VoucherTableName := 'SLSale';
ClientName.Open;
EmployeeName.Open;
GoodName.Open;
PackUnit.Open;
TempAds.close;
TempAds.CommandText :='select distinct levelcode from DAAttribute'
+' where name like'+Quotedstr('%商品%')+' and upid=-1';
TempAds.open;
TempAds.First;
GoodsSpecStr :=' where (1<>1 ';
while not TempAds.Eof do
begin
GoodsSpecStr :=GoodsSpecStr+' or Levelcode like '+Quotedstr('%'+
Trim(TempAds.fieldbyname('Levelcode').AsString)+'%') ;
TempAds.Next;
end;
GoodsSpecStr :=' select * from DAAttribute '+ GoodsSpecStr
+' ) and (upid<>-1 and Recordstate<>'+Quotedstr('删除')+')';
adsGoodsSpec.Close;
adsGoodsSpec.CommandText :=GoodsSpecStr;
adsGoodsSpec.Open;
TempAds.Close;
TempAds.CommandText :=' select Distinct brief from SLSaleMaster';
TempAds.Open;
TempAds.First;
while not TempAds.Eof do
begin
BriefComboBox.Items.Add(TempAds.FieldByName('brief').AsString);
TempAds.Next;
end;
if TempAds.IsEmpty then BriefComboBox.Items.Add('销售');
end;
procedure TSLEdSaleBGTPForm.FormShow(Sender: TObject);
begin
inherited;
ClientQLDBLookup.SetFocus;
end;
procedure TSLEdSaleBGTPForm.adsDetailGoodsIDChange(Sender: TField);
var SGoodsID,SUnitID,IsInGoods:integer;
begin
inherited;
if (adsDetail.fieldbyname('GoodsID').IsNull) or (adsDetail.fieldbyname('GoodsID').AsInteger=0)
then SGoodsID :=1 else SGoodsID :=adsDetail.fieldbyname('GoodsID').AsInteger;
TempAds.Close; //取标准单位和基本单价
TempAds.CommandText :='select UnitID,PriceSales from DAGoods where Id='
+ Inttostr(SGoodsID);
TempAds.Open;
if TempAds.FieldByName('UnitID').IsNull then SunitID :=1
else SunitID :=TempAds.FieldByName('UnitID').AsInteger;
// adsDetail.FieldByName('GoalUnitID').ReadOnly :=False;
adsDetail.FieldByName('GoalUnitID').AsInteger :=SunitID;
// adsDetail.FieldByName('GoalUnitID').ReadOnly :=True;
// adsDetail.FieldByName('PriceBase').ReadOnly :=False;
adsDetail.FieldByName('PriceBase').AsFloat := TempAds.FieldByName('PriceSales').AsFloat ;
if adsDetail.FieldByName('PriceBase').IsNull then adsDetail.FieldByName('PriceBase').AsFloat :=0;
IsInGoods :=0;
TpPackUnit.Close;
TpPackUnit.SQL.Text :='Truncate Table #TempPackUnit13 ';
TpPackUnit.ExecSQL;
TpPackUnit.Close;
TpPackUnit.SQL.Text :=' select a.AddUnitID ID, b.name,a.AddUnitRate '
+' ExchangeRate,a.UnitID GoalUnitID,b.IsGoalUnit '
+' from DAGoods a '
+' left outer join MSUnit b on b.ID=a.AddUnitID '
+' where a.AddUnitID is not null and AddUnitID<>0 and a.AddUnitRate '
+' is not null and a.AddUnitRate<>0 and a.ID= '+inttostr(SGoodsID) ;
TpPackUnit.Open;
if not TpPackUnit.IsEmpty then
begin
IsInGoods :=1;
TpPackUnit.Close; //将商品资料表的单位换算率插入 #TempPackUnit13
TpPackUnit.SQL.Text :=' insert into #TempPackUnit13 '
+' (ID, Name, ExchangeRate, GoalUnitID, IsGoalUnit )'
+'select a.AddUnitID ID, b.name,a.AddUnitRate '
+' ExchangeRate,a.UnitID GoalUnitID,b.IsGoalUnit '
+' from DAGoods a '
+' left outer join MSUnit b on b.ID=a.AddUnitID '
+' where a.AddUnitID is not null and AddUnitID<>0 and a.AddUnitRate '
+' is not null and a.AddUnitRate<>0 and a.ID= '+inttostr(SGoodsID) ;
TpPackUnit.ExecSQL;
end;
TpPackUnit.Close; //将单位资料表的换算率插入 #TempPackUnit13
TpPackUnit.SQL.Text :=' insert into #TempPackUnit13 '
+' (ID, Name, ExchangeRate, GoalUnitID, IsGoalUnit ) '
+' select ID, Name, ExchangeRate, GoalUnitID, IsGoalUnit '
+' from MSUnit where RecordState<>'+QuotedStr('删除')
+' Order by GoalUnitID,IsGoalUnit desc ';
TpPackUnit.ExecSQL;
PackUnit.Close; //显示单位列表与换算率
PackUnit.CommandText :=' select PID, ID, Name, ExchangeRate, GoalUnitID, IsGoalUnit '
+' from #TempPackUnit13 Order by PID';
PackUnit.Open;
if IsInGoods=0 then
begin
PackUnit.Locate('ID',Inttostr(SunitID),[]);
if not PackUnit.Eof then PackUnit.Next;
end else PackUnit.First;
adsDetail.FieldByName('PackUnitID').AsInteger :=PackUnit.FieldByName('ID').AsInteger;
end;
procedure TSLEdSaleBGTPForm.adsDetailPackUnitIDChange(Sender: TField);
var ExChRate :real;
begin
PackUnit.Locate('ID', adsDetail.fieldbyname('PackUnitID').AsString, []);
if PackUnit.fieldbyname('ExchangeRate').IsNull then ExChRate :=1
else ExChRate :=PackUnit.fieldbyname('ExchangeRate').AsFloat ;
// adsDetail.FieldByName('Quantity').ReadOnly :=False;
adsDetail.FieldByName('Quantity').AsFloat :=
adsDetail.fieldbyname('GoalQuantity').AsFloat/ExChRate;
// adsDetail.FieldByName('Quantity').ReadOnly :=True;
end;
procedure TSLEdSaleBGTPForm.adsDetailPriceBaseChange(Sender: TField);
begin
inherited;
// adsDetail.FieldByName('Amount').ReadOnly :=False;
adsDetail.FieldByName('Amount').AsFloat :=
adsDetail.fieldbyname('GoalQuantity').asfloat
*adsDetail.fieldbyname('PriceBase').AsFloat;
// adsDetail.FieldByName('Amount').ReadOnly :=True;
end;
procedure TSLEdSaleBGTPForm.SaveActionExecute(Sender: TObject);
var adoTemp: TADOQuery;
code:string;
MasterID:Integer;
begin
inherited;
if (adsMaster.fieldbyname('ID').AsInteger=0) or
(adsMaster.fieldbyname('ID').IsNull) then exit;
adoTemp := TADOQuery.Create(nil);
adoTemp.Connection := CommonData.acnConnection;
with adoTemp do
begin
//--------------判断将要插入的记录是否已经正在于SLGoodsOutMaster,不存在就插入
Close;
sql.Text :=' select b.ID from SLSaleDetail a '
+' left outer join SLSaleMaster b on a.MasterID=b.ID '
+' where isnull(a.goodsId,0)<>0 '
+' and isnull(a.GoalQuantity,0)<>0 '
+' and b.id=' + adsMaster.fieldbyname('ID').AsString
+' and b.RecordState<>' + QuotedStr('删除')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -