📄 pcedpurchase.pas
字号:
unit PCEdPurchase;
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
TPCEdPurchaseForm = 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;
PackUintFltAQ: TADODataSet;
PackUintFltDS: TDataSource;
NoCreditSale: TCheckBox;
adsDetailPriceGoal: TBCDField;
adsDetailPriceCost: TBCDField;
DBEdit6: TDBEdit;
adsMasterCashDiscount: TBCDField;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure adsDetailGoodsIDChange(Sender: TField);
procedure adsDetailQuantityChange(Sender: TField);
procedure ClientQLDBLookupEnter(Sender: TObject);
procedure ClientQLDBLookupExit(Sender: TObject);
procedure LookupPackUintEnter(Sender: TObject);
procedure NoCreditSaleClick(Sender: TObject);
procedure LookupPackUintExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure adsDetailPackUnitIDChange(Sender: TField);
private
{ Private declarations }
protected
// function CreateReport: TQuickRep; override;
procedure InternalSave; override;
public
{ Public declarations }
procedure Open(VoucherID: Integer); override;
procedure New; override;
end;
var
PCEdPurchaseForm: TPCEdPurchaseForm;
implementation
uses CommonDM, WSUtils, WSSecurity;
{$R *.dfm}
procedure TPCEdPurchaseForm.New;
begin
inherited; // .Value:=Date;
adsMaster.FieldByName('Date').AsDateTime:=Date;
adsMaster.FieldByName('Code').AsString:=GetMaxCode('Code','PCPurchaseMaster',number);
adsMaster.FieldByName('CreateUserID').AsInteger :=Guarder.UserID;
// adsMaster.FieldByName('BIllMode').ReadOnly :=False;
if NoCreditSale.Checked then adsMaster.FieldByName('BillMode').AsString:='现款采购'
else 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:='PCPurchaseMaster';
end;
procedure TPCEdPurchaseForm.Open(VoucherID: Integer);
var SaveOnClick: TNotifyEvent;
begin
inherited Open(VoucherID);
SaveOnClick := NoCreditSale.OnClick;
NoCreditSale.OnClick := nil;
if Trim(adsMaster.FieldByName('BillMode').AsString)='现款采购' then NoCreditSale.Checked :=True
else NoCreditSale.Checked :=False;
NoCreditSale.OnClick := SaveOnClick;
end;
procedure TPCEdPurchaseForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
adsMaster.Close;
adsDetail.Close;
ClientName.Close;
EmployeeName.Close;
GoodName.Close;
PackUnit.Close;
adsGoodsSpec.Close;
end;
procedure TPCEdPurchaseForm.FormCreate(Sender: TObject);
var GoodsSpecStr:string;
begin
inherited;
VoucherTableName := 'PCPurchase';
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 PCPurchaseMaster';
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 TPCEdPurchaseForm.adsDetailGoodsIDChange(Sender: TField);
var SGoodsID,SClientID:integer;
begin
inherited;
if (adsDetail.fieldbyname('GoodsID').IsNull) then exit;
SGoodsID :=adsDetail.fieldbyname('GoodsID').AsInteger;
if (adsMaster.fieldbyname('ClientID').IsNull) then SClientID :=0
else SClientID :=adsMaster.fieldbyname('ClientID').AsInteger;
TempAds.Close;
TempAds.CommandText :=' select ID,UnitID from DAGoods where ID='+inttostr(SGoodsID);
TempAds.Open;
if (TempAds.FieldByName('UnitID').IsNull) then
begin
adsDetail.FieldByName('GoalUnitID').AsInteger :=1;
adsDetail.FieldByName('PackUnitID').AsInteger :=1;
end else
begin
adsDetail.FieldByName('GoalUnitID').AsInteger :=TempAds.FieldByName('UnitID').AsInteger;
adsDetail.FieldByName('PackUnitID').AsInteger :=TempAds.FieldByName('UnitID').AsInteger;
end;
if Guarder.ContractPCPrice='是' then
begin
TempAds.Close; //取当前厂商的合同进价
TempAds.CommandText :=' SELECT b.Date,a.PriceGoal '
+' FROM PCContractPriceDetail a '
+' LEFT JOIN PCContractPriceMaster b on b.ID=a.MasterID '
+' where b.RecordState<>'+Quotedstr('删除')
+' and b.RecordState<>'+Quotedstr('作废')
+' and a.GoodsID='+inttostr(SGoodsID)
+' and b.ClientID='+inttostr(SClientID)
+' order by b.Date DESC ';
TempAds.Open;
end else
begin
TempAds.Close; //取当前厂商的合同进价
TempAds.CommandText :=' SELECT b.Date,a.PriceGoal '
+' FROM PCContractPriceDetail a '
+' LEFT JOIN PCContractPriceMaster b on b.ID=a.MasterID '
+' where 1=2 ' ;
TempAds.Open;
end;
if (Guarder.LastadjustPCPrice='是') and (TempAds.IsEmpty) then
begin
TempAds.Close; //取当前商品的最新采购调价
TempAds.CommandText :=' SELECT b.Date,a.PriceGoal '
+' FROM PCPurchasePriceDetail a '
+' LEFT JOIN PCPurchaseMaster b on b.ID=a.MasterID '
+' where b.RecordState<>'+Quotedstr('删除')
+' and b.RecordState<>'+Quotedstr('作废')
+' and a.GoodsID='+inttostr(SGoodsID)
+' order by b.Date DESC ';
TempAds.Open;
end;
if (Guarder.LastSLPrice='是') and (TempAds.IsEmpty) then
begin
TempAds.Close; //取当前商品,当前厂商的最新进价
TempAds.CommandText :=' SELECT b.Date,a.PriceGoal '
+' FROM PCPurchaseDetail a '
+' LEFT JOIN PCPurchaseMaster b on b.ID=a.MasterID '
+' where b.RecordState<>'+Quotedstr('删除')
+' and b.RecordState<>'+Quotedstr('作废')
+' and a.GoodsID='+inttostr(SGoodsID)
+' and b.ClientID='+inttostr(SClientID)
+' order by b.Date DESC ';
TempAds.Open;
end;
if TempAds.IsEmpty then
begin
TempAds.Close; //取当前商品的参考进价
TempAds.CommandText :=' SELECT PricePurchase PriceGoal '
+' FROM DAGoods '
+' where RecordState<>'+Quotedstr('删除')
+' and RecordState<>'+Quotedstr('作废')
+' and ID='+inttostr(SGoodsID);
TempAds.Open;
end;
adsDetail.FieldByName('PriceGoal').AsFloat := TempAds.FieldByName('PriceGoal').AsFloat ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -