package com.topsun.posclient.sales.dialog; import java.math.BigDecimal; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; import com.co.lane.util.StringUtil; import com.topsun.posclient.common.LoggerUtil; import com.topsun.posclient.common.POSException; import com.topsun.posclient.common.ui.style.CommonCss; import com.topsun.posclient.datamodel.Item; import com.topsun.posclient.datamodel.UnSalePart; import com.topsun.posclient.sales.core.service.IPartSaleService; import com.topsun.posclient.sales.core.service.impl.PartSaleServiceImpl; import com.topsun.posclient.sales.ui.gold.PartSalesFacade; import com.topsun.posclient.sales.ui.gold.PartSalesManager; import com.topsun.posclient.sales.ui.menu.SalesActivator; /** * * 断头对话框 * * @author yujie creator * */ public class CutGoldDialog extends Dialog { private String selfQ = "";//原克重 private Text salesQ;//销售克重 private Text cutQ;//断头克重 private String docNum; // 零售页面带过来的单据编号 protected void configureShell(Shell newShell) { newShell.setText("断头"); super.configureShell(newShell); } public final String getDocNum() { return docNum; } public final void setDocNum(String docNum) { this.docNum = docNum; } public Text getSalesQ() { return salesQ; } public void setSalesQ(Text salesQ) { this.salesQ = salesQ; } public Text getCutQ() { return cutQ; } public void setCutQ(Text cutQ) { this.cutQ = cutQ; } public String getSelfQ() { return selfQ; } public void setSelfQ(String totalQ) { this.selfQ = totalQ; } public CutGoldDialog(Shell parent) { super(parent); } public CutGoldDialog(Shell parent, String selfQ) { super(parent); this.selfQ = selfQ; } @Override protected void okPressed() { String salesQStr = salesQ.getText(); if(StringUtil.isEmpty(salesQStr)){ MessageDialog.openError(cutQ.getShell(), "错误", "【销售克重】不能为空"); salesQ.forceFocus(); return; } String cutQstr = cutQ.getText(); if(StringUtil.isEmpty(cutQstr)){ MessageDialog.openError(cutQ.getShell(), "错误", "【断头克重】不能为空"); cutQ.forceFocus(); return; } if(!StringUtil.isNumber(cutQstr) || !StringUtil.isNumber(salesQStr) ){ MessageDialog.openError(cutQ.getShell(), "错误", "克重只能为数字"); return; } if(new BigDecimal(salesQStr).compareTo(new BigDecimal(selfQ)) == 1){ MessageDialog.openError(salesQ.getShell(), "错误", "【销售克重】不能大于原克重"); return; } if(new BigDecimal(cutQstr).compareTo(new BigDecimal(selfQ)) == 1){ MessageDialog.openError(cutQ.getShell(), "错误", "【断头克重】不能大于原克重"); return; } if(new BigDecimal(cutQstr).add(new BigDecimal(salesQStr)).compareTo(new BigDecimal(selfQ)) == 1){ MessageDialog.openError(cutQ.getShell(), "错误", "【断头克重+销售克重】不能大于原克重"); return; } BigDecimal modifyQ = new BigDecimal(salesQ.getText()); Item item = PartSalesFacade.getCurrentSelectionItem(); item.setZDPZL(modifyQ); item.setSalesAmount(modifyQ.multiply(item.getPrice()).add(item.getFactZJGF()));//断头之后修改更新应售价 item.setFactAmount(item.getSalesAmount());//断头之后修改更新实售价 IPartSaleService iPartSaleService = new PartSaleServiceImpl(); BigDecimal currentPrice; try { currentPrice = iPartSaleService.getGoldPriceByMtartCode(item.getMatkl()); PartSalesManager.getInstance().getSalesProductTableView().update(item, null); UnSalePart part = new UnSalePart(); // part.setMainID(Integer.valueOf(item.getItemCode())); // 单据ID part.setItemCode(item.getItemCode()); // 单品编号 part.setIdfCode(item.getMATNR()); // 物料编码 part.setSourceCode(item.getItemCode()); // 原单品编号 part.setDocNum(docNum); BigDecimal palWeight = new BigDecimal(selfQ).subtract(new BigDecimal(salesQStr)).subtract(new BigDecimal(cutQstr)); part.setPalWeight(palWeight); // 损益重量 原克重-销售克重-截断克重 part.setPalAmount(palWeight.multiply(currentPrice)); // 损益金额 part.setPalAccount(palWeight.multiply(currentPrice)); part.setWeight(new BigDecimal(cutQstr)); // 断料净重 就是断头克重 part.setWeight_F(new BigDecimal(cutQstr)); // 实际重量 和断料净重一样 part.setPrice_G(currentPrice); // 金价 part.setType("经销"); part.setPrice_A(new BigDecimal(selfQ).multiply(currentPrice)); // 结算金额 item.setUnSalePart(part); for(Item tempItem : PartSalesManager.getInstance().getItemTempList()){ if(item.getItemCode().equals(tempItem.getItemCode())){ tempItem.setUnSalePart(part); tempItem.setZDPZL(modifyQ); tempItem.setSalesAmount(modifyQ.multiply(item.getPrice()).add(item.getFactZJGF()));//断头之后修改更新应售价 tempItem.setFactAmount(item.getSalesAmount());//断头之后修改更新实售价 } } PartSalesManager.getInstance().getSalesProductTableView().refresh(); PartSalesFacade.caculatorPartSalesPrice(); } catch (POSException e) { LoggerUtil.logError(SalesActivator.PLUGIN_ID, e.getErrorMessage(), e); MessageDialog.openInformation(this.getShell(), "错误", "断料数据保存失败"); return; } super.okPressed(); } protected Control createContents(Composite parent) { Composite compsite = new Composite(parent, SWT.BORDER); compsite.setLayout(new GridLayout(2, false)); GridData layoutData = new GridData(GridData.FILL_BOTH); compsite.setLayoutData(layoutData); { Label label = new Label(compsite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data); label.setText("总重量(g):"); } { Text text = new Text(compsite, SWT.BORDER); GridData data = new GridData(GridData.FILL_HORIZONTAL); text.setFont(CommonCss.getDefaultFont(parent.getDisplay())); data.widthHint = 150; text.setLayoutData(data); text.setEditable(false); text.setText(selfQ); } { Label label = new Label(compsite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data); label.setText("销售克重:"); } { salesQ = new Text(compsite, SWT.BORDER); salesQ.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(GridData.FILL_HORIZONTAL); salesQ.setFocus(); data.widthHint = 150; salesQ.setLayoutData(data); } { Label label = new Label(compsite, SWT.NONE); label.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data); label.setText("断头克重:"); } { cutQ = new Text(compsite, SWT.BORDER); cutQ.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData data = new GridData(GridData.FILL_HORIZONTAL); data.widthHint = 150; cutQ.setLayoutData(data); } return super.createContents(parent); } protected void createButtonsForButtonBar(Composite parent) { int buttonWidth = 80; int buttonHight = 45; parent.setLayout(new GridLayout(5,false)); Button okbtn = createButton(parent, IDialogConstants.OK_ID, "确定",true); okbtn.setFont(CommonCss.getDefaultFont(parent.getDisplay())); GridData btnLayout = new GridData(); btnLayout.widthHint = buttonWidth; btnLayout.heightHint = buttonHight; okbtn.setLayoutData(btnLayout); Button cancelBtn = createButton(parent, IDialogConstants.CANCEL_ID, "取消", false); cancelBtn.setFont(CommonCss.getDefaultFont(parent.getDisplay())); cancelBtn.setLayoutData(btnLayout); } protected Button createButton(Composite parent, int id, String label, boolean defaultButton) { return super.createButton(parent, id, label, defaultButton); } }