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

📄 sledsalecloth.pas

📁 详细的ERP设计资料
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit SLEdSaleCloth;

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
  TSLEdSaleClothForm = class(TBaseVoucherEditForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    ClientName: TADODataSet;
    EmployeeName: TADODataSet;
    GoodName: TADODataSet;
    Label5: TLabel;
    GoodsSpecAds: TADODataSet;
    GoodsSpecDs: TDataSource;
    DSClientName: TDataSource;
    DSEmployeeName: TDataSource;
    ClientQLDBLookup: TQLDBLookupComboBox;
    LookupEmployee: TQLDBLookupComboBox;
    Label6: TLabel;
    Label7: TLabel;
    GoodsSpecLKUP: 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;
    Label10: TLabel;
    DBEdit3: TDBEdit;
    DBEdit4: TDBEdit;
    Label4: TLabel;
    DBEdit5: TDBEdit;
    GEdit1: TGEdit;
    adsDetailTaxAmount: TBCDField;
    adsDetailGoodsSpec: TStringField;
    adsMasterEmployee: TStringField;
    GoalUnit: TADODataSet;
    dsGoalUnit: TDataSource;
    adsDetailGoalUnit: TStringField;
    adsMasterModeDC: TIntegerField;
    adsMasterModeC: TIntegerField;
    adsMasterWarehouseID: TIntegerField;
    TempActualCost: TADODataSet;
    adsDetailPriceCost: TBCDField;
    adsDetailGoodsName: TStringField;
    TpPackUnit: TADOQuery;
    NoCreditSale: TCheckBox;
    CapStyleAds: TADODataSet;
    CapStyleDs: TDataSource;
    N33: TMenuItem;
    FilePrintAction: TAction;
    adsDetailPriceGoal: TBCDField;
    DBEdit6: TDBEdit;
    adsMasterCashDiscount: TBCDField;
    adsDetailCapStyle: TStringField;
    adsDetailSizeA: TIntegerField;
    adsDetailSizeB: TIntegerField;
    adsDetailSizeC: TIntegerField;
    adsDetailSizeD: TIntegerField;
    adsDetailSizeE: TIntegerField;
    adsDetailSizeF: TIntegerField;
    CapStyleLKup: TQLDBLookupComboBox;
    SameQuantityAct: TAction;
    N41: TMenuItem;
    QLDBLookupComboBox1: TQLDBLookupComboBox;
    WareHouseIDADS: TADODataSet;
    WareHouseIDDS: TDataSource;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure adsDetailGoodsIDChange(Sender: TField);
    procedure ClientQLDBLookupEnter(Sender: TObject);
    procedure ClientQLDBLookupExit(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure adsDetailGoalQuantityChange(Sender: TField);
    procedure FilePrintActionExecute(Sender: TObject);
    procedure adsDetailPackUnitIDChange(Sender: TField);
    procedure NoCreditSaleClick(Sender: TObject);
    procedure DBEdit6Enter(Sender: TObject);
    procedure adsDetailSizeAChange(Sender: TField);
    procedure SameQuantityActExecute(Sender: TObject);
    procedure adsDetailQuantityPcsChange(Sender: TField);
  private
    { Private declarations }
  protected
    function CreateReport: TQuickRep; override;
    procedure InternalSave; override;
  public
     SLPubQuerrySql,SLPubQuerryCaption,NewOrEditFlag:string;
    { Public declarations }
    procedure Open(VoucherID: Integer); override;
    procedure New; override;

  end;

var
  SLEdSaleClothForm: TSLEdSaleClothForm;

implementation
                          
uses CommonDM, WSUtils, WSSecurity, SLRpSale, BaseVoucherRpt,CRCtrls, Math, QLDBAgg;

{$R *.dfm}
procedure TSLEdSaleClothForm.New;
begin
  inherited;
  adsMaster.FieldByName('Date').AsDateTime:=Date;
  adsMaster.FieldByName('Code').AsString:=GetMaxCode('Code','SLSaleMaster',number);
  adsMaster.FieldByName('CreateUserID').AsInteger :=Guarder.UserID;
  if NoCreditSale.Checked then   adsMaster.FieldByName('BillMode').AsString:='现款销售'
    else   adsMaster.FieldByName('BillMode').AsString:='销售开单';
  adsMaster.FieldByName('ModeDC').AsInteger :=1;
  adsMaster.FieldByName('ModeC').AsInteger :=1;
  adsMaster.FieldByName('Deliver').AsString:='--';
  adsMaster.FieldByName('OriginTable').AsString:='SLSaleMaster';
  NewOrEditFlag :='新增状态';
end;

procedure TSLEdSaleClothForm.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 TSLEdSaleClothForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  adsMaster.Close;
  adsDetail.Close;
  ClientName.Close;
  EmployeeName.Close;
  GoodName.Close;
  GoodsSpecAds.Close;
  CapStyleAds.Close;
end;

procedure TSLEdSaleClothForm.FormCreate(Sender: TObject);
var GoodsSpecStr:string;
begin
  inherited;
  VoucherTableName := 'SLSale';
  ClientName.Open;
  EmployeeName.Open;
  GoodName.Open;
  CapStyleAds.Open;
  GoodsSpecAds.Open;
  WareHouseIDADS.Open;
end;

procedure TSLEdSaleClothForm.adsDetailGoodsIDChange(Sender: TField);
var SGoodsID,SUnitID,SClientID,IsInGoods: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 a.GoodsID, a.PriceGoal PriceSales,c.UnitID, '
      +' a.GoodsSpec FROM SLSaleDetail a '
      +' left outer join SLSaleMaster b on b.ID=a.MasterID '
      +' left outer join DAGoods c      on c.ID=a.GoodsID '
      +' where b.Recordstate<>'+QuotedStr('删除')
      +' and b.ClientID='+ Inttostr(SClientID)
      +' and a.GoodsID='+Inttostr(SGoodsID)
      +' and Isnull(a.PriceGoal,0)<>0 '
      +' order by  b.Date,b.ID desc ';
  TempAds.Open;

  //如果当前客户当前商品没有单价,取当前商品资料的参考售价为最新售价
  //以后客户需要更多种类的单价,可以用CASE来处理
  if TempAds.IsEmpty then
  begin
    TempAds.Close;
    TempAds.CommandText :=' SELECT ID GoodsID, PriceSales ,UnitID,Spec  '
        +' GoodsSpec FROM DAGoods  '
        +' where Recordstate<>'+QuotedStr('删除')
        +' and Isnull(PriceSales,0)<>0 '
        +' and ID='+Inttostr(SGoodsID) ;
    TempAds.Open;
  end;

  if  TempAds.FieldByName('UnitID').IsNull then SunitID :=1
    else SunitID :=TempAds.FieldByName('UnitID').AsInteger;
  adsDetail.FieldByName('GoalUnitID').AsInteger :=SunitID;
  adsDetail.FieldByName('PackUnitID').AsInteger :=SunitID;

  TempActualCost.Close;
  TempActualCost.CommandText :=' select CostPrice from #TpCostPrice'
    +' where GoodsID= '+ Inttostr(SGoodsID) ;
  TempActualCost.Open;
  adsDetail.FieldByName('PriceGoal').AsFloat := TempAds.FieldByName('PriceSales').AsFloat  ;
  adsDetail.FieldByName('PriceCost').AsFloat := TempActualCost.FieldByName('CostPrice').AsFloat  ;
end;

procedure TSLEdSaleClothForm.ClientQLDBLookupEnter(Sender: TObject);
begin
  inherited;
  GEdit1.Enabled :=true;
  GEdit1.Text :='0';
  GEdit1.Enabled :=false;
end;

procedure TSLEdSaleClothForm.ClientQLDBLookupExit(Sender: TObject);
var  adoTemp: TADOQuery;
     FstDate:Tdatetime;
begin
  inherited;
  if   (adsMaster.fieldbyname('ClientID').IsNull) or
          (adsMaster.fieldbyname('ClientID').AsInteger=0)  then exit;
  adoTemp := TADOQuery.Create(nil);
  adoTemp.Connection := CommonData.acnConnection;
  with adoTemp do
  begin
    close;
    sql.Text :=' select sum(isnull(AmountD,0)) as Balance from '
    +' (  select (isnull(a.amount,0)-isnull(a.Discount,0)+isnull(a.TaxAmount,0) '
    +' +isnull(a.SundryFee,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1) as amountD                         '
    +' from  SLSaleDetail a                                                     '
    +' left outer join  SLSaleMaster b on b.ID=a.MasterID                       '
    +' where b.RecordState<>'+Quotedstr('删除')+' and b.ClientID='
    + adsMaster.fieldbyname('ClientID').AsString
    +' UNION ALL                                                   '
    +' select (isnull(a.amount,0)-isnull(a.Discount,0)+isnull(a.TaxAmount,0) '
    +' +isnull(a.SundryFee,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1)*(-1) as amountD                 '
    +' from  PCPurchaseDetail a                                              '
    +' left outer join  PCPurchaseMaster b on b.ID=a.MasterID                '
    +' where b.RecordState<>'+Quotedstr('删除')+' and b.ClientID='
    + adsMaster.fieldbyname('ClientID').AsString
    +' UNION ALL                                                             '
    +' select (Isnull(AmountD,0)+Isnull(AmountRed,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1)*(-1)     '
    +' as AmountD                                                            '
    +' from FNClearSLMaster                                                  '
    +' where RecordState<>'+Quotedstr('删除')+' and ClientID='
    + adsMaster.fieldbyname('ClientID').AsString
    +' UNION ALL                                                             '
    +' select (Isnull(AmountC,0)+Isnull(AmountRed,0) )*Isnull(ModeDC,1)*Isnull(ModeC,1)          '
    +' as AmountD                                                            '
    +' from FNClearPCMaster                                                  '
    +' where RecordState<>'+Quotedstr('删除')+' and ClientID='
    + adsMaster.fieldbyname('ClientID').AsString +'  ) as a ';
    open;
    GEdit1.Enabled :=true;
    if  adoTemp.IsEmpty then     GEdit1.Text :='0'
      else   GEdit1.Text :=fieldbyname('Balance').asstring;
    GEdit1.Enabled :=False;
    close;
    sql.Text :=' select QuotaAmountMin from SLCredit where '
        +' RecordState<>'+ Quotedstr('删除')
        +' and ClientID='+ adsMaster.fieldbyname('ClientID').AsString ;
    open;

    if (NewOrEditFlag='新增状态') and not (fieldbyname('QuotaAmountMin').IsNull) then
    begin
      adsMaster.Edit;
      adsMaster.fieldbyname('ClearDate').AsDateTime :=
          adsMaster.fieldbyname('Date').AsDateTime+ fieldbyname('QuotaAmountMin').AsInteger
    end;
  end;
end;

procedure TSLEdSaleClothForm.FormActivate(Sender: TObject);
var  adoTemp: TADOQuery;
begin
  inherited;
  adoTemp := TADOQuery.Create(nil);
  adoTemp.Connection := CommonData.acnConnection;
  adoTemp.Close;
  adoTemp.SQL.Text :=' IF EXISTS(  SELECT * FROM tempdb..sysobjects '
        +' WHERE ID = OBJECT_ID('+Quotedstr('tempdb..#TpCostPrice')
        +' )) DROP TABLE #TpCostPrice '   ;
  adoTemp.ExecSQL;
  adoTemp.Close;
  adoTemp.SQL.Text :=' select a.GoodsID, c.UnitID GoalUnitID , '
    +' Sum(isnull(a.GoalQuantity,0)*Isnull(ModeDC,1)*Isnull(ModeC,1)) GoalQuantity, '
    +' Sum(isnull(a.Amount,0)*Isnull(ModeDC,1)*Isnull(ModeC,1)) CostPrice , '
    +' Sum(isnull(a.Amount,0)*Isnull(ModeDC,1)*Isnull(ModeC,1)) Amount '
    +' Into #TpCostPrice from PCgoodsIndetail a '
    +' left outer join PCPurchaseMaster b on b.id=a.MasterID '
    +' left outer join  DAGoods         c on c.id=a.GoodsID '
    +' WHERE Isnull(a.Amount,0)+Isnull(a.GoalQuantity,0) <>0 '
    +' and b.RecordState<>'+Quotedstr('删除')
    +' and b.RecordState<>'+Quotedstr('作废')
    +' group by a.GoodsID ,c.UnitID  ';
  adoTemp.ExecSQL;
  adoTemp.Close;
  adoTemp.SQL.Text :=' Update #TpCostPrice  set CostPrice =Null  ';
  adoTemp.ExecSQL;
  adoTemp.Close;
  adoTemp.SQL.Text :=' Update #TpCostPrice  set CostPrice = '
     +' Isnull(Amount,0)/GoalQuantity where Isnull(GoalQuantity,0) <>0 ';
  adoTemp.ExecSQL;

  adoTemp.Close;
  adoTemp.SQL.Text :=' Insert Into #TpCostPrice (GoodsID,GoalUnitID, '

⌨️ 快捷键说明

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