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

📄 sledsalecloth.pas

📁 详细的ERP设计资料
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    +' GoalQuantity, CostPrice , Amount )'
    +' Select ID GoodsID,UnitID GoalUnitID, PricePurchase CostPrice, '
    +' 1,1   from DAGoods   '
    +' WHERE RecordState<>'+Quotedstr('删除')
    +' and ID Not In (Select GoodsID from #TpCostPrice)' ;
  adoTemp.ExecSQL;
  ClientQLDBLookup.SetFocus;
end;

function TSLEdSaleClothForm.CreateReport: TQuickRep;
begin
  Result := TSLSaleVoucherReport.Create(Self);
  TBaseVoucherReport(Result).SetMasterDataSet(MasterDataSet);
end;

procedure TSLEdSaleClothForm.adsDetailGoalQuantityChange(Sender: TField);
begin
  adsDetail.Edit;
  adsDetail.FieldByName('Amount').AsFloat :=
    adsDetail.fieldbyname('GoalQuantity').AsFloat*adsDetail.fieldbyname('PriceGoal').AsFloat;
  adsDetail.Edit;
  adsDetail.FieldByName('Quantity').AsFloat :=adsDetail.fieldbyname('GoalQuantity').AsFloat;
  adsDetail.Edit;
  adsDetail.FieldByName('PriceBase').AsFloat :=adsDetail.fieldbyname('PriceGoal').AsFloat;
end;

procedure TSLEdSaleClothForm.FilePrintActionExecute(Sender: TObject);

  function CurrencyUpperCaseHitch(Value: Currency): string;

    function OnesPlace(X: Double): Integer;
    begin
      Result := Trunc(X);
      Result := Result - Result div 10 * 10;
    end;

  var
    I, N: Integer;
    S: string;
  begin
    Result := '';
    Value := Round(Value * Power(10, 2)) / Power(10, 2);
    for I := 7 downto 0 do
    begin
      N := OnesPlace(Value / Power(10, I - 2));
      S := NumberToHZ(N, 1);
      if S = '' then S := '零';
      if Result = '' then Result := S
      else Result := Result + '     ' + S;
    end;
  end;

var
  ExePath: string;
  S1, S2, S3, S4, S5, S6, S7: string;
begin
  inherited;
  ExePath := ExtractFilePath(Application.ExeName);
  with DetailDataSet do
  begin
    First;
    while not Eof do
    begin
      S1 := S1 + #13#10 + FieldByName('GoodsName').DisplayText;
      S2 := S2 + #13#10 + FieldByName('GoodsSpec').DisplayText;
      S3 := S3 + #13#10 + FieldByName('GoalUnit').DisplayText;
      S4 := S4 + #13#10 + FieldByName('GoalQuantity').DisplayText;
      S5 := S5 + #13#10 + FieldByName('PriceGoal').DisplayText;
      S6 := S6 + #13#10 + FieldByName('Amount').DisplayText;
      S7 := S7 + #13#10 + FieldByName('Memo').DisplayText;
      Next;
    end;
  end;
  with TReportRuntime.Create(Self) do
  begin
    ReportFile := ExePath + 'Reports\Sale.ept';
    SetDataSet('Master', MasterDataSet);
    SetDataSet('Detail', DetailDataSet);
    SetVarValue('S1', S1);
    SetVarValue('S2', S2);
    SetVarValue('S3', S3);
    SetVarValue('S4', S4);
    SetVarValue('S5', S5);
    SetVarValue('S6', S6);
    SetVarValue('S7', S7);
    SetVarValue('QuantityTotal', CurrToStrF(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'GoalQuantity').AggregateValue, ffFixed, 2));
    SetVarValue('AmountTotal', CurrToStrF(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'Amount').AggregateValue, ffCurrency, 2));
    SetVarValue('AmountTotalHZ', CurrencyUpperCaseHitch(DBGrid.AggregateList.Aggregates.FindAggregate(atSum, 'Amount').AggregateValue));
    PrintPreview(True);
  end;
end;

procedure TSLEdSaleClothForm.adsDetailPackUnitIDChange(Sender: TField);
var ExChRate :real;
begin
end;

procedure TSLEdSaleClothForm.NoCreditSaleClick(Sender: TObject);
begin
  if NoCreditSale.Checked then
  begin
    adsMaster.Edit;
    if pos(Trim(NoCreditSale.Caption),Trim(adsMaster.FieldByName('Memo').AsString))<=0 then
      adsMaster.FieldByName('Memo').AsString :=
          Copy( Trim(NoCreditSale.Caption)+Trim(adsMaster.FieldByName('Memo').AsString),1,60);
    adsMaster.FieldByName('BillMode').AsString :='现款销售';
    RemarkDBEdit.ReadOnly :=True;
  end else
  begin
    adsMaster.Edit;
    if pos(Trim(NoCreditSale.Caption),Trim(adsMaster.FieldByName('Memo').AsString))>0 then
      adsMaster.FieldByName('Memo').AsString :=
        StringReplace( Trim(adsMaster.FieldByName('Memo').AsString) ,
          Trim(NoCreditSale.Caption),'',[rfReplaceAll, rfIgnoreCase]);
    adsMaster.FieldByName('BillMode').AsString :='销售开单';
    RemarkDBEdit.ReadOnly :=False;
  end;
  DBEdit6.ReadOnly :=not NoCreditSale.Checked;
  if DBEdit6.ReadOnly then
  begin
    adsMaster.Edit;
    adsMaster.FieldByName('CashDiscount').Value :=null;
  end;
end;

procedure TSLEdSaleClothForm.DBEdit6Enter(Sender: TObject);
begin
  DBEdit6.ReadOnly :=not NoCreditSale.Checked;
  if DBEdit6.ReadOnly then
  begin
    adsMaster.Edit;
    adsMaster.FieldByName('CashDiscount').Value :=null;
  end;
end;
procedure TSLEdSaleClothForm.InternalSave;
var adoTemp: TADOQuery;
    code,AccountIDStr,MasterIDStr,IDStr: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
        code :=GetMaxCode('Code','SLGoodsOutMaster',number);
        close;
        sql.Text := 'insert into SLGoodsOutMaster ( CreateUserID,'
            +' Date, Code, ClientID, EmployeeID, BillMode,  '
            +' ModeDC,ModeC, Brief, ClearDate, SundryFee, Apportion,  '
            +' Deliver, Memo, BillAffix ,OriginID, OriginTable ) '
            +' select CreateUserID,Date, '+ QuotedStr(code)+ ' ,'
            +' ClientID, EmployeeID,BillMode ,'
            +' ModeDC,ModeC, '+QuotedStr('销售开单自动提交') +' ,'
            +' ClearDate, SundryFee, Apportion, '
            +' Deliver, '+ QuotedStr('销售单号:')
            +' +code, BillAffix, ID, '+QuotedStr('SLSaleMaster')
            +' from SLSaleMaster '
            +' where id=' +adsMaster.fieldbyname('ID').AsString
            +' and RecordState<>'+QuotedStr('删除')
            +' and ID not in '
            +' (select top 1 OriginID from SLGoodsOutMaster where '
            +' OriginTable='+ QuotedStr('SLSaleMaster')
            +' and OriginID='+adsMaster.fieldbyname('ID').AsString+'  )';
        ExecSQL; //插入出库主表记录完毕
        close;
        sql.Text := 'select top 1 ID from SLGoodsOutMaster  where '
            +' OriginTable='+ QuotedStr('SLSaleMaster')
            +' and OriginID='+adsMaster.fieldbyname('ID').AsString;
        open;
        if adoTemp.IsEmpty then MasterID :=0
            else MasterID :=adoTemp.FieldByName('ID').AsInteger;
        sql.Text := 'insert into SLGoodsOutDetail ( '
              +' MasterID, GoodsID, GoodsSpec,    '
              +' Quantity, QuantityPcs, PackUnitID,  '
              +' GoalUnitID, GoalQuantity, Memo )   '
              +' select '+ Inttostr(MasterID) + ' , a.GoodsID, a.GoodsSpec, '
              +' a.Quantity, a.QuantityPcs, a.PackUnitID, '
              +' a.GoalUnitID, a.GoalQuantity, a.Memo  '
              +' 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 a.MasterID='+ adsMaster.fieldbyname('ID').AsString
              +' and b.RecordState<>'+QuotedStr('删除');
        ExecSQL;//插入出库子表记录完毕
        close;
        Sql.Text :=' update SLGoodsOutDetail set '
            +' SLGoodsOutDetail.PriceGoal=#TpCostPrice.Costprice '
            +' from SLGoodsOutDetail left outer join  #TpCostPrice '
            +' on #TpCostPrice.goodsid=SLGoodsOutDetail.goodsid '
            +' where MasterID='+ Inttostr(MasterID);
        Execsql;
        close;
        Sql.Text :=' update  SLGoodsOutDetail set Amount=GoalQuantity*PriceGoal '
             +' where MasterID= '+ Inttostr(MasterID);
        ExecSQL;
        close;
        Sql.Text :=' update  SLGoodsOutDetail set PriceBase=Amount/Quantity'
             +' where Quantity<>0 and MasterID= '+ Inttostr(MasterID);
        ExecSQL;

        //计算销售产品的临时成本单价完毕
    end;
  end;
//判断是否要插入销售结算表
  if ( adsMaster.FieldByName('BillMode').AsString ='现款销售' )  then
  begin
//    Exit;
    adoTemp.Close;
    adoTemp.SQL.Text :='select OriginID from FNClearSLMaster'
        +' where OriginTable='+Quotedstr('SLSaleMaster')
        +' and RecordState<>'+Quotedstr('删除')+' and OriginID='
        + adsMaster.fieldbyname('ID').AsString ;
    adoTemp.Open;
    if adoTemp.IsEmpty then
    begin
      adoTemp.Close;
      adoTemp.SQL.Text :=' select * from FNAccounts '
          +' where AccountType like '+Quotedstr('%现金%')
          +' and RecordState<>'+Quotedstr('删除') ;
      adoTemp.open;

      AccountIDStr :=adoTemp.fieldbyname('ID').AsString;
      if Trim(AccountIDStr)='' then AccountIDStr :='1';

      IDStr :=adsMaster.fieldbyname('ID').AsString;
      if Trim(IDStr)='' then IDStr :='0';
      adoTemp.Close;
      adoTemp.SQL.Text :=' Insert into FNClearSLMaster ('
          +' CreateUserID,Date,Code,BillMode,ModeDC,ModeC,'
          +' Brief, ClientID, EmployeeID,AccountsID, AmountD,   '
          +' AmountC,AmountRed,Memo, OriginID, OriginTable)     '
          +' select  CreateUserID, Date,                        '
          +Quotedstr(GetMaxCode('Code','FNClearSLMaster',number))+' , '
          +Quotedstr('现销结算')+' BillMode, ModeDC, ModeC, '
          +Quotedstr('现款销售')+' as Brief,         '
          +' ClientID, EmployeeID, '+ AccountIDStr+' as  AccountID , '
          +' (isnull(b.Amount,0)+isnull(a.SundryFee,0)-isnull(CashDiscount,0) )'
          +' as AmountD, '
          +' 0.00,CashDiscount,   '
          +Quotedstr('现款销售')+' as Memo, a.ID, '
          +Quotedstr('SLSaleMaster')
          +' from SLSaleMaster a                                 '
          +' left outer join                                     '
          +' ( select MasterID,Sum(Isnull(Amount,0)) as Amount   '
          +' from SLSaleDetail                                   '
          +' Group by MasterID ) b on B.MasterID=a.ID            '
          +' where a.ID='+IDStr  ;
      adoTemp.ExecSQL;

      AccountIDStr := adsMaster.fieldbyname('ID').AsString;
      if Trim(AccountIDStr)='' then AccountIDStr :='0';

      adoTemp.Close;
      adoTemp.SQL.Text :='select ID from FNClearSLMaster '
          +' where OriginID='+AccountIDStr+' and OriginTable='
          +Quotedstr('SLSaleMaster') ;
      adoTemp.Open; //选定新插入记录(FNClearSLMaster表)的ID号
      MasterIDStr :=adoTemp.fieldbyname('ID').AsString;
      if Trim(MasterIDStr)='' then MasterIDStr :='0';

      adoTemp.Close;
      adoTemp.SQL.Text :=' Insert into FNClearSLDetail ('
          +' MasterID,OriginID,Amount)'
          +' select  '+MasterIDStr +'as MasterID,'
          +' a.ID as OriginID, '
          +' (isnull(b.Amount,0)+isnull(a.SundryFee,0) ) as Amount '
          +' from SLSaleMaster a                                 '
          +' left outer join                                     '
          +' ( select MasterID,Sum(Isnull(Amount,0)) as Amount   '
          +' from SLSaleDetail                                   '
          +' Group by MasterID ) b on B.MasterID=a.ID            '
          +' where a.ID='+IDStr  ;
    adoTemp.ExecSQL;
    end;
  end;
end;

procedure TSLEdSaleClothForm.adsDetailSizeAChange(Sender: TField);
begin
  inherited;
  adsDetail.Edit;
  adsDetail.FieldByName('GoalQuantity').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat
    +adsDetail.fieldbyname('SizeB').AsFloat+adsDetail.fieldbyname('SizeC').AsFloat
    +adsDetail.fieldbyname('SizeD').AsFloat+adsDetail.fieldbyname('SizeE').AsFloat
//    +adsDetail.fieldbyname('SizeF').AsFloat;
    +adsDetail.fieldbyname('SizeF').AsFloat+adsDetail.fieldbyname('QuantityPcs').AsFloat  ;
end;

procedure TSLEdSaleClothForm.SameQuantityActExecute(Sender: TObject);
begin
  inherited;
  if adsDetail.fieldbyname('SizeA').AsFloat=0 then
  begin
  adsDetail.Edit;
    adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('SizeB').AsFloat;
    if adsDetail.fieldbyname('SizeA').AsFloat=0 then
      adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('SizeC').AsFloat;
    if adsDetail.fieldbyname('SizeA').AsFloat=0 then
      adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('SizeD').AsFloat;
    if adsDetail.fieldbyname('SizeA').AsFloat=0 then
      adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('SizeE').AsFloat;
    if adsDetail.fieldbyname('SizeA').AsFloat=0 then
      adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('SizeF').AsFloat;
  end;
  adsDetail.Edit;
  adsDetail.FieldByName('SizeB').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
  adsDetail.FieldByName('SizeC').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
  adsDetail.FieldByName('SizeD').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
  adsDetail.FieldByName('SizeE').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
  adsDetail.FieldByName('SizeF').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
//  adsDetail.FieldByName('QuantityPcs').AsFloat :=adsDetail.fieldbyname('SizeA').AsFloat;
end;

procedure TSLEdSaleClothForm.adsDetailQuantityPcsChange(Sender: TField);
begin
  EXIT;
  inherited;
  adsDetail.Edit;
  adsDetail.FieldByName('SizeA').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
  adsDetail.FieldByName('SizeB').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
  adsDetail.FieldByName('SizeC').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
  adsDetail.FieldByName('SizeD').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
  adsDetail.FieldByName('SizeE').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
  adsDetail.FieldByName('SizeF').AsFloat :=adsDetail.fieldbyname('QuantityPcs').AsFloat/6;
end;

end.

⌨️ 快捷键说明

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