📄 sledsalegoalunittopack.pas
字号:
unit SLEdSaleGoalUnitToPack;
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, QuickRpt;
type
TSLEdSaleGoalUnitToPackForm = 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;
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;
adsDetailGoodsName: 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;
LookupGoodsSpec: TQLDBLookupComboBox;
adsGoodsSpec: TADODataSet;
dsGoodsSpec: TDataSource;
adsMasterEmployee: TStringField;
GoalUnit: TADODataSet;
dsGoalUnit: TDataSource;
adsDetailGoalUnit: TStringField;
adsMasterModeDC: TIntegerField;
adsMasterModeC: TIntegerField;
adsMasterWarehouseID: TIntegerField;
TempActualCost: TADODataSet;
adsDetailPriceCost: TBCDField;
adsDetailPackUnit: TStringField;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
// procedure adsDetailQuantityChange(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 }
protected
function CreateReport: TQuickRep; override;
public
SLPubQuerrySql,SLPubQuerryCaption,NewOrEditFlag:string;
{ Public declarations }
procedure Open(VoucherID: Integer); override;
procedure New; override;
end;
var
SLEdSaleGoalUnitToPackForm: TSLEdSaleGoalUnitToPackForm;
implementation
uses CommonDM, WSUtils, WSSecurity, SLRpSale, BaseVoucherRpt;
{$R *.dfm}
procedure TSLEdSaleGoalUnitToPackForm.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('ModeDC').AsInteger :=1;
adsMaster.FieldByName('ModeC').AsInteger :=1;
adsMaster.FieldByName('Deliver').AsString:='--';
adsMaster.FieldByName('Apportion').AsString:='--';
adsMaster.FieldByName('OriginTable').AsString:='SLSaleMaster';
NewOrEditFlag :='新增状态';
end;
procedure TSLEdSaleGoalUnitToPackForm.Open(VoucherID: Integer);
begin
inherited Open(VoucherID);
end;
procedure TSLEdSaleGoalUnitToPackForm.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
adsMaster.Close;
adsDetail.Close;
ClientName.Close;
EmployeeName.Close;
GoodName.Close;
PackUnit.Close;
adsGoodsSpec.Close;
end;
procedure TSLEdSaleGoalUnitToPackForm.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('销售');
NewOrEditFlag :='编辑状态';
end;
procedure TSLEdSaleGoalUnitToPackForm.adsDetailGoodsIDChange(Sender: TField);
var SGoodsID,SUnitID,SClientID:integer;
begin
inherited;
if (adsDetail.fieldbyname('GoodsID').IsNull) or (adsDetail.fieldbyname('GoodsID').AsInteger=0)
then SGoodsID :=0 else SGoodsID :=adsDetail.fieldbyname('GoodsID').AsInteger;
if (adsMaster.fieldbyname('ClientID').IsNull) or (adsMaster.fieldbyname('ClientID').AsInteger=0)
then SClientID :=0 else SClientID :=adsMaster.fieldbyname('ClientID').AsInteger;
TempAds.Close; //取当前客户的合同售价和标准单位
TempAds.CommandText :='select GoalUnitID UnitID,PriceClear PriceSales '
+' from SLContractpriceDetail a '
+' Left Outer Join SLContractpriceMaster b on b.ID=A.masterID '
+' where a.PriceClear<>0 and b.RecordState<>'+QuotedStr('删除')
+' and b.RecordState<>'+QuotedStr('注销')
+' and b.ClientID= '+ Inttostr(SClientID)
+' and GoodsID= '+ Inttostr(SGoodsID) ;
TempAds.Open;
if TempAds.IsEmpty then
begin
TempAds.Close; //取标准单位和基本单价
TempAds.CommandText :='select UnitID,PriceSales from DAGoods where Id='
+ Inttostr(SGoodsID);
TempAds.Open;
end;
TempActualCost.Close;
TempActualCost.CommandText :=' select CostPrice from #TpCostPrice'
+' where GoodsID= '+ Inttostr(SGoodsID) ;
TempActualCost.Open;
adsDetail.FieldByName('GoalUnitID').ReadOnly :=False;
if (TempAds.FieldByName('UnitID').IsNull) or (TempAds.FieldByName('UnitID').AsInteger=0) then
adsDetail.FieldByName('GoalUnitID').AsInteger :=1
else
adsDetail.FieldByName('GoalUnitID').AsInteger :=TempAds.FieldByName('UnitID').AsInteger;
adsDetail.FieldByName('PriceBase').ReadOnly :=False;
adsDetail.FieldByName('PriceBase').AsFloat := TempAds.FieldByName('PriceSales').AsFloat ;
if not TempActualCost.FieldByName('CostPrice').IsNull then
adsDetail.FieldByName('PriceCost').AsFloat := TempActualCost.FieldByName('CostPrice').AsFloat ;
if adsDetail.FieldByName('PriceBase').IsNull then adsDetail.FieldByName('PriceBase').AsFloat :=0;
if TempAds.FieldByName('UnitID').IsNull then SunitID :=1
else SunitID :=TempAds.FieldByName('UnitID').AsInteger;
{select ID, Name, ExchangeRate, GoalUnitID, IsGoalUnit
from MSUnit where RecordState<>'删除' }
PackUnit.Close; //取该商品的其它包装单位
PackUnit.CommandText :='select a.AddUnitID ID, b.name, a.AddUnitRate '
+' ExchangeRate,b.GoalUnitID,b.IsGoalUnit '
+' from DAGoods a '
+' Left outer join MSUnit b on a.AddUnitID=b.ID'
+' where a.ID= '+ Inttostr(SGoodsID)+' and '
+' a.RecordState<>'+Quotedstr('删除')+' and '
+' a.AddUnitID is not null and a.AddUnitID<>0 and'
+' a.AddUnitRate <>0 and '
+' a.RecordState<>'+Quotedstr('注销');
PackUnit.Open;
showmessage(Inttostr(SGoodsID)+' -- '+PackUnit.FieldByName('ID').AsString);
adsDetail.FieldByName('PackUnitID').ReadOnly :=False;
if not (PackUnit.FieldByName('ID').IsNull) then
adsDetail.FieldByName('PackUnitID').AsInteger :=PackUnit.FieldByName('ID').AsInteger
else adsDetail.FieldByName('PackUnitID').AsInteger :=adsDetail.FieldByName('GoalUnitID').AsInteger;
adsDetail.FieldByName('PackUnitID').ReadOnly :=True;
end;
procedure TSLEdSaleGoalUnitToPackForm.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 TSLEdSaleGoalUnitToPackForm.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('删除')
+' and b.ID not in '
+' (select top 1 OriginID from SLGoodsOutMaster where '
+' OriginTable='+ QuotedStr('SLSaleMaster')
+' and OriginID='+adsMaster.fieldbyname('ID').AsString+' )';
open;
if not adoTemp.IsEmpty then //判断完毕,开始插入
begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -