Inheritance: TransportationActBillBase
    public IList<TransportationActBill> PopulateSelectedData()
    {
        if (this.GV_List.Rows != null && this.GV_List.Rows.Count > 0)
        {
            IList<TransportationActBill> transportationActBillList = new List<TransportationActBill>();
            foreach (GridViewRow row in this.GV_List.Rows)
            {
                CheckBox checkBoxGroup = row.FindControl("CheckBoxGroup") as CheckBox;
                if (checkBoxGroup.Checked)
                {
                    HiddenField hfId = row.FindControl("hfId") as HiddenField;
                    TextBox tbQty = row.FindControl("tbQty") as TextBox;
                    TextBox tbAmount = row.FindControl("tbAmount") as TextBox;
                    TextBox tbDiscount = row.FindControl("tbDiscount") as TextBox;

                    TransportationActBill transportationActBill = new TransportationActBill();
                    transportationActBill.Id = int.Parse(hfId.Value);
                    transportationActBill.CurrentBillQty = decimal.Parse(tbQty.Text);
                    transportationActBill.CurrentBillAmount = decimal.Parse(tbAmount.Text);
                    transportationActBill.CurrentDiscount = decimal.Parse(tbDiscount.Text);

                    transportationActBillList.Add(transportationActBill);
                }
            }
            return transportationActBillList;
        }

        return null;
    }
 public virtual void UpdateTransportationActBill(TransportationActBill entity)
 {
     Update(entity);
 }
 public virtual void CreateTransportationActBill(TransportationActBill entity)
 {
     Create(entity);
 }
 public virtual void DeleteTransportationActBill(TransportationActBill entity)
 {
     Delete(entity);
 }
        public TransportationBillDetail TransferTransportationActBill2TransportationBillDetail(TransportationActBill transportationActBill)
        {
            EntityPreference entityPreference = this.entityPreferenceMgr.LoadEntityPreference(
                BusinessConstants.ENTITY_PREFERENCE_CODE_AMOUNT_DECIMAL_LENGTH);
            int amountDecimalLength = int.Parse(entityPreference.Value);
            TransportationBillDetail transportationBillDetail = new TransportationBillDetail();
            transportationBillDetail.ActBill = transportationActBill;

            transportationBillDetail.TransType = transportationActBill.TransType;
            transportationBillDetail.Currency = transportationActBill.Currency;
            transportationBillDetail.IsIncludeTax = transportationActBill.IsIncludeTax;
            transportationBillDetail.TaxCode = transportationActBill.TaxCode;

            /*
             *
             * 1.TransType=Transportation �۸���ϸ�������̣� ��  �̲��ѣ�����ʱ
             * a.PricingMethod=M3��KG  ������
             * b.SHIPT   �����
             * 2.TransType=WarehouseLease(�̶�����) �����
             * 3.TransType=Operation(������) ������
             */
            if (transportationActBill.TransType == BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_OPERATION
                ||
                (transportationActBill.TransType == BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION
                && (transportationActBill.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_M3 || transportationActBill.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_KG)
                )
                )
            {
                transportationBillDetail.UnitPrice = transportationActBill.UnitPrice;
                transportationBillDetail.BilledQty = transportationActBill.CurrentBillQty;
                transportationBillDetail.Discount = transportationActBill.CurrentDiscount;
                if (transportationActBill.CurrentBillQty != (transportationActBill.BillQty - transportationActBill.BilledQty))
                {
                    //���ο�Ʊ��������ʣ������
                    if (transportationActBill.CurrentBillQty > (transportationActBill.BillQty - transportationActBill.BilledQty))
                    {
                        throw new BusinessErrorException("TransportationActBill.Error.CurrentBillQtyGeRemainQty");
                    }

                    //���ο�Ʊ����С��ʣ������
                    transportationBillDetail.Amount = Math.Round((transportationActBill.BillAmount / transportationActBill.BillQty * transportationActBill.CurrentBillQty), amountDecimalLength, MidpointRounding.AwayFromZero);
                }
                else
                {
                    //���ο�Ʊ��������ʣ������
                    transportationBillDetail.Amount = transportationActBill.BillAmount - transportationActBill.BilledAmount;
                }
            }
            else
            {
                transportationBillDetail.UnitPrice = transportationActBill.CurrentBillAmount;
                transportationBillDetail.BilledQty = 1;
                transportationBillDetail.Discount = transportationActBill.CurrentDiscount;
                if (transportationActBill.CurrentBillAmount != (transportationActBill.BillAmount - transportationActBill.BilledAmount))
                {
                    //���ο�Ʊ������ʣ����
                    if (transportationActBill.CurrentBillAmount > (transportationActBill.BillAmount - transportationActBill.BilledAmount))
                    {
                        throw new BusinessErrorException("TransportationActBill.Error.CurrentBillAmountGeRemainAmount");
                    }

                    //���ο�Ʊ���С��ʣ����
                    transportationBillDetail.Amount = transportationActBill.CurrentBillAmount;
                }
                else
                {
                    //���ο�Ʊ������ʣ����
                    transportationBillDetail.Amount = transportationActBill.BillAmount - transportationActBill.BilledAmount;
                }
            }

            return transportationBillDetail;
        }
        public TransportationActBill CreateTransportationActBill(TransportationOrder order, User user)
        {
            TransportationActBill actBill = new TransportationActBill();
            if (order.Expense != null)
            {

                actBill.BillAmount = order.Expense.Amount;
                actBill.UnitPrice = order.Expense.Amount;
                actBill.BillQty = 1;
                actBill.Currency = order.Expense.Currency;
                actBill.IsIncludeTax = order.Expense.IsIncludeTax;
                actBill.Currency.Code = order.Expense.Currency.Code;
                actBill.IsProvisionalEstimate = false;

            }
            else
            {
                string currency = null;
                foreach (TransportationOrderDetail orderDetail in order.OrderDetails)
                {
                    #region currency
                    if (orderDetail.InProcessLocation.Flow.Currency == null)
                    {
                        throw new BusinessErrorException("Transportation.Flow.CurrencyEmpty", orderDetail.InProcessLocation.Flow.Code);
                    }
                    if (currency == null)
                    {
                        currency = orderDetail.InProcessLocation.Flow.Currency.Code;
                    }
                    else if (currency != orderDetail.InProcessLocation.Flow.Currency.Code)
                    {
                        throw new BusinessErrorException("Transportation.OrderDetail.CurrencyNotEqual");
                    }
                    #endregion
                }

                IList<TransportPriceList> transportPriceList = transportPriceListMgr.GetTransportPriceList(order.Carrier.Code);
                if (transportPriceList == null || transportPriceList.Count == 0)
                {
                    throw new BusinessErrorException("Transportation.PriceList.Empty", order.Carrier.Code);
                }
                if (transportPriceList.Count > 1)
                {
                    throw new BusinessErrorException("Transportation.PriceList.MoreThanOne", order.Carrier.Code);
                }

                TransportPriceListDetail priceListDetail = null;
                if (order.PricingMethod != BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                {
                    priceListDetail = this.transportPriceListDetailMgr.GetLastestTransportPriceListDetail(transportPriceList[0]
                       , order.CreateDate, currencyMgr.LoadCurrency(currency), order.PricingMethod, order.TransportationRoute.ShipFrom, order.TransportationRoute.ShipTo, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION, order.VehicleType,order.TransportMethod);

                }

                #region ����
                if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_SHIPT)
                {
                    actBill.BillQty = 1;
                    if (priceListDetail != null && actBill.UnitPrice == 0)
                    {
                        actBill.UnitPrice = priceListDetail.UnitPrice;
                        actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                    }
                }
                #endregion

                #region ����ͽ���
                else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_M3 || order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                {
                    decimal totalVolume = 0;
                    foreach (TransportationOrderDetail orderDetail in order.OrderDetails)
                    {
                        foreach (InProcessLocationDetail ipDet in orderDetail.InProcessLocation.InProcessLocationDetails)
                        {
                            if (!ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.HasValue || ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.Value == 0)
                            {
                                throw new BusinessErrorException("Transportation.PackageVolumn.Empty", ipDet.InProcessLocation.IpNo, ipDet.OrderLocationTransaction.Item.Code);
                            }
                            else
                            {
                                if (ipDet.OrderLocationTransaction.OrderDetail.HuLotSize == null || ipDet.OrderLocationTransaction.OrderDetail.HuLotSize.Value == 0)
                                {
                                    throw new BusinessErrorException("Transportation.HuLotSize.Empty", ipDet.InProcessLocation.IpNo, ipDet.OrderLocationTransaction.Item.Code);
                                }
                                int box = Convert.ToInt32(Math.Ceiling(ipDet.Qty / (decimal)(ipDet.OrderLocationTransaction.OrderDetail.HuLotSize.Value)));
                                totalVolume += ipDet.OrderLocationTransaction.OrderDetail.PackageVolumn.Value * box;
                            }
                        }
                    }

                    #region ������
                    if (order.PallentCount != 0)
                    {

                        decimal pallentVolume = decimal.Parse(entityPreferenceMgr.LoadEntityPreference(
                                BusinessConstants.ENTITY_PREFERENCE_CODE_PALLENTVOLUME).Value);
                        totalVolume += pallentVolume * order.PallentCount;
                    }
                    #endregion

                    if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_M3)
                    {
                        #region ��������
                        if (totalVolume < priceListDetail.MinVolume)
                        {
                            totalVolume = priceListDetail.MinVolume;
                        }
                        #endregion

                        actBill.BillQty = totalVolume;
                        if (priceListDetail != null && actBill.UnitPrice == 0)
                        {
                            actBill.UnitPrice = priceListDetail.UnitPrice;
                        }
                        actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                    }
                    #region ����
                    else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_LADDERSTERE)
                    {
                        priceListDetail = this.transportPriceListDetailMgr.GetLastestLadderStereTransportPriceListDetail(transportPriceList[0], null, order.CreateDate, currencyMgr.LoadCurrency(currency), null, order.PricingMethod, order.TransportationRoute.ShipFrom, order.TransportationRoute.ShipTo, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION, null, order.VehicleType, totalVolume);
                        if (priceListDetail == null)
                        {
                            throw new BusinessErrorException("Transportation.PriceListDetail.Empty", order.PricingMethod);
                        }

                        #region ��������
                        if (totalVolume < priceListDetail.MinVolume)
                        {
                            totalVolume = priceListDetail.MinVolume;
                        }
                        #endregion
                        actBill.UnitPrice = priceListDetail.UnitPrice;
                        actBill.BillQty = totalVolume;
                        decimal minPrice = priceListDetail.MinPrice.HasValue ? priceListDetail.MinPrice.Value : 0;
                        actBill.BillAmount = minPrice + actBill.UnitPrice * actBill.BillQty;
                    }
                    #endregion
                }
                #endregion

                #region ����
                else if (order.PricingMethod == BusinessConstants.TRANSPORTATION_PRICING_METHOD_KG)
                {

                }
                #endregion

                else
                {
                    throw new BusinessErrorException("Transportation.PricingMethod.Empty");
                }

                actBill.UnitPrice = priceListDetail.UnitPrice;
                // actBill.BillAmount = actBill.UnitPrice * actBill.BillQty;
                actBill.Currency = priceListDetail.Currency;
                actBill.IsIncludeTax = priceListDetail.IsIncludeTax;
                actBill.Currency = priceListDetail.Currency;
                actBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
                actBill.PricingMethod = order.PricingMethod;
                actBill.PriceList = priceListDetail.TransportPriceList;
                actBill.PriceListDetail = priceListDetail;
                actBill.VehicleType = priceListDetail.VehicleType;
                if (order.TransportationRoute != null)
                {
                    actBill.ShipFrom = order.TransportationRoute.ShipFrom;
                    actBill.ShipTo = order.TransportationRoute.ShipTo;
                }
            }

            actBill.OrderNo = order.OrderNo;
            actBill.BillAddress = order.CarrierBillAddress;
            actBill.EffectiveDate = DateTime.Parse(order.CreateDate.ToString("yyyy-MM-dd"));
            actBill.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
            actBill.TransType = BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_TRANSPORTATION;
            actBill.CreateDate = DateTime.Now;
            actBill.CreateUser = user;
            actBill.LastModifyDate = DateTime.Now;
            actBill.LastModifyUser = user;
            actBill.TransportMethod = order.TransportMethod;
            this.CreateTransportationActBill(actBill);
            return actBill;
        }
        public TransportationActBill CreateTransportationItemActBill(Receipt receipt, string billingMethod)
        {
            TransportationActBill actBill = new TransportationActBill();
            TransportPriceList transportPriceList = null;
            if (billingMethod == BusinessConstants.TRANSPORTATION_BILLING_METHOD_OUT)
            {
                transportPriceList = transportPriceListMgr.LoadTransportPriceList(receipt.PartyFrom.Code);
            }
            if (transportPriceList != null)
            {
                Currency currency = receipt.ReceiptDetails[0].OrderLocationTransaction.OrderDetail.OrderHead.Currency;

                foreach (ReceiptDetail receiptDetail in receipt.ReceiptDetails)
                {
                    TransportPriceListDetail priceListDetail = transportPriceListDetailMgr.GetLastestTransportPriceListDetail(transportPriceList, receiptDetail.OrderLocationTransaction.Item,
                          receipt.CreateDate, currency, receiptDetail.OrderLocationTransaction.OrderDetail.Item.Uom, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_OPERATION, billingMethod);

                    if (priceListDetail != null)
                    {
                        priceListDetail = transportPriceListDetailMgr.GetLastestTransportPriceListDetail(transportPriceList, null,
                          receipt.CreateDate, currency, null, BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_OPERATION, billingMethod);
                    }

                    actBill.BillAddress = billAddressMgr.GetDefaultBillAddress(priceListDetail.TransportPriceList.Party.Code);
                    actBill.PriceListDetail = priceListDetail;
                    actBill.PriceList = priceListDetail.TransportPriceList;
                    actBill.UnitPrice = priceListDetail.UnitPrice * (1 + priceListDetail.ServiceCharge);
                    actBill.TransType = BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_OPERATION;

                    actBill.BillQty = receiptDetail.ReceivedQty.Value;
                    actBill.BillAmount = actBill.BillQty * actBill.UnitPrice;
                    actBill.Currency = priceListDetail.Currency;
                    actBill.EffectiveDate = DateTime.Now.Date;
                    actBill.CreateDate = DateTime.Now;
                    actBill.CreateUser = userMgr.GetMonitorUser();
                    actBill.IsIncludeTax = priceListDetail.IsIncludeTax;
                    actBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
                    actBill.LastModifyDate = DateTime.Now;
                    actBill.LastModifyUser = userMgr.GetMonitorUser();
                    actBill.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
                    actBill.TaxCode = priceListDetail.TaxCode;

                }
            }
            return actBill;
        }
        public void CreateTransportationActBill(TransportPriceListDetail priceListDetail)
        {
            TransportationActBill actBill = new TransportationActBill();
            actBill.BillAddress = billAddressMgr.GetDefaultBillAddress(priceListDetail.TransportPriceList.Party.Code);

            if (actBill.BillAddress == null)
            {
                throw new BusinessErrorException("Transportation.Error.CarrierPrimaryBillAddressEmpty");
            }

            actBill.PriceListDetail = priceListDetail;
            actBill.PriceList = priceListDetail.TransportPriceList;
            actBill.UnitPrice = priceListDetail.UnitPrice * (1 + priceListDetail.ServiceCharge);
            actBill.TransType = BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_WAREHOUSELEASE;

            actBill.BillQty = 1;
            actBill.BillAmount = actBill.BillQty * actBill.UnitPrice;
            actBill.Currency = priceListDetail.Currency;
            actBill.EffectiveDate = DateTime.Now.Date;
            actBill.CreateDate = DateTime.Now;
            actBill.CreateUser = userMgr.GetMonitorUser();
            actBill.IsIncludeTax = priceListDetail.IsIncludeTax;
            actBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
            actBill.LastModifyDate = DateTime.Now;
            actBill.LastModifyUser = userMgr.GetMonitorUser();
            actBill.Status = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
            actBill.TaxCode = priceListDetail.TaxCode;

            CreateTransportationActBill(actBill);
        }
Exemple #9
0
    protected void createTBill()
    {
        TransportationOrder to = TheTransportationOrderMgr.LoadTransportationOrder(OrderNo);
        if (to.Status == "In-Process")
        {
        TransportationActBill tb = new TransportationActBill();
        tb.BillAddress=TheBillAddressMgr.LoadBillAddress(((Controls_TextBox)(this.FV_Order.FindControl("tbCarrierBillAddress"))).Text);
        tb.Currency =TheCurrencyMgr.LoadCurrency("RMB");
        tb.Status="Create";
        tb.IsIncludeTax = false;
        tb.OrderNo = this.OrderNo;
        tb.TransType = "Transportation";
        tb.EffectiveDate = DateTime.Now;
        tb.CreateDate = DateTime.Now;
        tb.CreateUser = CurrentUser;
        tb.LastModifyUser = CurrentUser;
        tb.LastModifyDate = DateTime.Now;
        tb.IsProvisionalEstimate = false;
        string carrier=string.Empty;
        tb.PricingMethod = ((com.Sconit.Control.CodeMstrDropDownList)(this.FV_Order.FindControl("ddlPricingMethod"))).SelectedValue;
        carrier=((Controls_TextBox)(this.FV_Order.FindControl("tbCarrier"))).Text + "WL";
         string vchtype = ((DropDownList)(this.FV_Order.FindControl("ddlType"))).SelectedValue;
        int shipto=(TheTransportationOrderMgr.LoadTransportationOrder(this.OrderNo)).TransportationRoute.ShipTo.Id;
        int shipfrom=(TheTransportationOrderMgr.LoadTransportationOrder(this.OrderNo)).TransportationRoute.ShipFrom.Id;
        DataSet ds = SqlHelper.ExecuteDataset(connstring, CommandType.Text, "select id from TPriceListDet where Tpricelist='" + carrier + "' and startdate<'" + to.CreateDate.ToShortDateString() + "' and enddate >'" + to.CreateDate.ToShortDateString() + "' and currency='RMB' and pricingmethod='" + tb.PricingMethod + "' and vehicletype='" + vchtype + "' and shipto='" + shipto + "' and shipfrom='" + shipfrom + "' ");
        if (ds.Tables[0].Rows.Count == 0)
        {
            throw new BusinessErrorException("没有找到该类型的价格单");

        }
        int _id = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
        tb.PriceListDetail=TheTransportPriceListDetailMgr.LoadTransportPriceListDetail(_id);
        tb.PriceList = TheTransportPriceListMgr.LoadTransportPriceList(carrier);
        tb.UnitPrice = tb.PriceListDetail.UnitPrice;
        tb.ShipFrom = tb.PriceListDetail.ShipFrom;
        tb.ShipTo = tb.PriceListDetail.ShipTo;
        tb.VehicleType = tb.PriceListDetail.VehicleType;
        if (tb.PricingMethod != "SHIPT")
        {
            decimal qty = 0;
            foreach (DataRow dr in ds_ip.Tables[0].Rows)
            {
                qty += Convert.ToDecimal((TheInProcessLocationMgr.LoadInProcessLocation(dr["ipno"].ToString())).CompleteLatency);
            }
            tb.BillQty = qty;
            tb.BilledQty = 0;
            if (qty < tb.PriceListDetail.MinVolume)
                tb.BillAmount = tb.PriceListDetail.MinVolume * tb.UnitPrice;
            else
                tb.BillAmount = qty * tb.UnitPrice;
            tb.BilledAmount = 0;
        }
        else
        {
            tb.BillQty = 1;
            tb.BilledQty = 0;
            tb.BillAmount=tb.PriceListDetail.UnitPrice;
            tb.BilledAmount=0;
        }
        TheTransportationActBillMgr.CreateTransportationActBill(tb);
        }
        else
            return ;
    }