📄 sal_enter_passshiporder.pas
字号:
AdoQry_Body.First;
while(not AdoQry_Body.Eof)do
begin
if BatchCtrl(AdoQry_Tmp,AdoQry_Body.fieldbyname('ItemCode').AsString)
and(AdoQry_Body.fieldbyname('BatchNo').AsString='') then
begin
DispString:='该物料受批次控制,但没有批次号,不能审核!';
Abort;
end;
if (AdoQry_Body.fieldbyname('BatchNo').AsString<>'') then
begin
if not BatchCtrl(AdoQry_Tmp,AdoQry_Body.fieldbyname('ItemCode').AsString)then
begin
DispString:='该物料不受批次控制,不能有批次号!';
Abort;
end;
if not BatchNoCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
AdoQry_Body.fieldbyname('ItemCode').AsString,'',MEdt_CreateDate.Text) then
Abort;
end;
SqlText := 'update InvOutBillLine '
+' set '//InvBillQty=('+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'),'
+' InvBillAmount='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillPrice, '
+' InvBillAmountC='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillPriceC, '
+' InvBillNoTaxAmountC='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillNoTaxPriceC, '
+' InvBillNoTaxAmount='+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+'*InvBillNoTaxPrice '
+' where InvBillId = '+AdoQry_Body.fieldbyname('InvBillId').AsString
+' and InvBillLineNo = '+AdoQry_BoDy.fieldbyname('InvBillLineNo').asString;;
ExecuteSql(AdoQry_Tmp,sqltext,1) ;
SqlText := 'select * from InvOutBillLine '
+' where InvBillId = '+AdoQry_Body.fieldbyname('InvBillId').AsString
+' and InvBillLineNo = '+AdoQry_BoDy.fieldbyname('InvBillLineNo').asString;;
ExecuteSql(AdoQry_Tmp,SqlText,0);
SqlText := 'update Sa_SaleOrderLine '
+' set ShipQty=IsNull(ShipQty,0)+('+floattostr(AdoQry_Body.fieldbyname('InvBillqty').asfloat)+')'+','
+' PrepareShipQty=IsNull(PrepareShipQty,0)-('+FloatToStr(AdoQry_Tmp.fieldbyname('InvBillQty').AsFloat)+')'
+' where SloNo='+QuotedStr(AdoQry_Body.fieldbyname('SloNo').AsString)
+' and SloLineNo='+AdoQry_Body.fieldbyname('SloLineNo').AsString;
ExecuteSql(AdoQry_Tmp,sqltext,1) ;
//如果当前仓库计价方式是移动加权,且此刻可更新移动加权时
if (PriceType=0)then
begin
if(True)then
begin
SqlText:='If Not Exists'
+' (Select ItemCode'
+' From AveragePrice'
+' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+''')'
+' Insert AveragePrice(WHCode,ItemCode)'
+' Values('
+' '''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+')';
ExecuteSql(AdoQry_Tmp,SqlText,1);
{单据保存,更改移动加权平均价:如果ApQty<>0,则使用原来的算法
否则ApQty=ApQty-(出库数)ApAmount=ApAmount-出库数量*AveragePrice
AveragePrice保持不变}
SqlText:='Update AveragePrice Set '
+' ApAmount=ApAmount-(Case When ApQty=0 Then AveragePrice'
+' Else ApAmount/ApQty end)*('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')'
+' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,1);
SqlText:='Update AveragePrice Set'
+' ApQty=ApQty-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+') '
+' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,1);
SqlText:='Select Case When ApQty=0 Then AveragePrice'
+' Else ApAmount/ApQty end As AveragePrice'
+' From AveragePrice'
+' Where WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
ExecuteSql(AdoQry_tmp,SqlText,0);
Bill_Count:=AdoQry_Tmp.fieldbyname('AveragePrice').AsString;
end
else
begin
Bill_Count:='0';
end
end
else
begin
SqlText:='Select SPPrice'
+' From StandardPrice'
+' Where SPStArtMonth='''+Copy(MEdt_CreateDate.Text,1,7)+''''
+' And ItemCode='''+AdoQry_Body.fieldbyname('ItemCode').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,0);
Bill_Count:=AdoQry_Tmp.fieldbyname('SPPrice').AsString;
end;
if Bill_Count='' then
Bill_Count:='0';
SqlText:='Update InvOutBillLine Set'
// +' InvBillNoTaxPrice='+Bill_Count+''
+' InvBillQty='+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+',BillLineRemArk='''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+' Where InvBillLineNo='''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+''''
+' And InvBillId='''+AdoQry_Head.fieldbyname('InvBillId').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,1);
{ SqlText:='Update InvOutBillLine Set'
+' InvBillNoTaxAmount=Round(InvBillNoTaxPrice*InvBillQty,2)'
+' Where InvBillLineNo='''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+''''
+' And InvBillId='''+AdoQry_Head.fieldbyname('InvBillId').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,1);
}
//因为数量变动了,重新计算实际售出金额
SqlText := 'Update RealSalePrice Set'
+' InvBillSaleAmount=InvBillSalePrice*'+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+',InvBillNoTaxSaleAmount=InvBillNoTaxSalePrice*'+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+' Where InvBillLineNo='''+AdoQry_Body.fieldbyname('InvBillLineNo').AsString+''''
+' And InvBillId='''+AdoQry_Head.fieldbyname('InvBillId').AsString+'''';
ExecuteSql(AdoQry_Tmp,SqlText,1);
//更新当前库存
Tempstr:=UpdateInv(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString
,AdoQry_Head.fieldbyname('WhPositionCode').AsString
,AdoQry_Body.fieldbyname('ItemCode').AsString
,'(-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'))'
,NeedChangePrice,True);
if Tempstr<>'' then
begin
DispString:=Tempstr;
DispInfo(DispString,3);
Abort;
end;
if AdoQry_Body.fieldbyname('BatchNo').AsString<>'' then
begin
if not BatchInvCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('WhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat)then
Abort;
ChangeBatchInv(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',MEdt_CreateDate.Text,AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('WhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
end;
AdoQry_Body.Next;
end;
SqlText := 'update InvOutBill '
+' set TotalInvBillAmount='+Edt_TotalTaxAmount.Text +','
+' TotalInvBillAmountC=ExchRate*('+Edt_TotalTaxAmount.Text+'),'
+' TotalInvBillNoTaxAmountC=ExchRate*('+Edt_TotalNoTaxAmount.Text+'),'
+' TotalInvBillNoTaxAmount='+Edt_TotalNoTaxAmount.Text
+' where InvBillNo = '+QuotedStr(Edt_ShipNo.Text);
ExecuteSql(AdoQry_Tmp,SqlText,1);
CreateOutBill(Edt_ShipNo.Text);
DBConnect.CommitTrans;
DispInfo('销售发货出库核定完毕!',3);
except
If Dbconnect.InTransaction then
DBConnect.RollBackTrans;
DispInfo('销售发货出库核定失败!',3);
Abort;
end;
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('InvBillWHChck').AsInteger:=1;
AdoQry_Head.fieldbyname('InvBillDate').AsString:=MEdt_CreateDate.Text;
AdoQry_Head.Post;
Cx_Assess.ItemIndex := 1;
Edt_AssessorEmployeeCode.Text := UserCode;
ExecuteSql(AdoQry_tmp,'select EmployeeName from Employee where EmployeeCode='+QuotedStr(Edt_AssessorEmployeeCode.Text),0);
Edt_AssessName.Text := AdoQry_Tmp.fieldbyname('EmployeeName').AsString;
Act_Check.Enabled:=False;
MEdt_CreateDate.Enabled:=False;
end;
procedure TFrm_Sal_Enter_PassShipOrder.Act_CancelCheckExecute(
Sender: TObject);
var
SqlText:String;
begin
inherited;
If (AdoQry_Head.Eof) And (AdoQry_Head.Bof) Then
Exit;
If Cx_Assess.ItemIndex = 1 then
If (DispInfo('确认要取消审核这张销售发货单吗?',2)='y') Then
begin
Dbconnect.beginTrans ;
saveShipOrderHistory(dbconnect,edt_Shipno.text,userCode,4);
SQlText:=' UpDate Sa_ShipOrder Set Assess=0, '
+' AssessorEmployeeCode='''' Where ShipNo='''+Edt_ShipNo.Text+''' ';
AdoQry_Tmp.Close;
AdoQry_Tmp.sql.clear ;
AdoQry_Tmp.SQL.Text := SqlText;
AdoQry_Tmp.ExecSQL ;
updateqty(1);
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('Assess').AsInteger:=0;
AdoQry_Head.fieldbyname('AssessorEmployeeCode').AsString:='';
AdoQry_Head.Post;
Cx_Assess.ItemIndex :=0;
Edt_AssessorEmployeeCode.Text := '';
edt_assessName.Text:='' ;
Dbconnect.CommitTrans;
end;
end;
function TFrm_Sal_Enter_PassShipOrder.enoughCurrentInv(whCode,WhPositionCode,ItemCode:string;qty:real):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select onhandInv from CurrentInv '
+' where whCode='+quotedstr(whCode)
+' and WhPositionCode='+quotedstr(WhPositionCode)
+' and ItemCode='+quotedstr(ItemCode);
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
if AdoQry.fieldbyname('onhandInv').asfloat>=qty then
Result:=True;
finally
AdoQry.Free;
end;
end;
function TFrm_Sal_Enter_PassShipOrder.enoughBatchInv(Batchno,whCode,WhPositionCode:string;qty:real):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
sqltext:='select InvQty from BatchCurrentInv '
+' where whCode='+quotedstr(whCode)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -