예제 #1
0
        void saveDN(ProcessTransaction pt, int count, DataRow row)
        {
            int     stt = TextUtils.ToInt(row["F1"]);
            decimal qty = TextUtils.ToDecimal(row["F7"]);

            C_QuotationDetail_SXModel item = new C_QuotationDetail_SXModel();

            item.C_QuotationID = Quotation.ID;
            item.ParentID      = 0;
            item.Qty           = item.QtyT = qty;
            item.PriceVT       = TextUtils.ToDecimal(row["F41"]);
            item.PriceVTTN     = TextUtils.ToDecimal(row["F42"]);
            item.PriceVTPS     = TextUtils.ToDecimal(row["F43"]);
            item.Manufacture   = TextUtils.ToString(row["F4"]);
            item.ModuleCode    = TextUtils.ToString(row["F3"]);
            item.ModuleName    = TextUtils.ToString(row["F2"]);
            item.Origin        = TextUtils.ToString(row["F5"]);

            item.C_ProductGroupID = TextUtils.ToInt(LibQLSX.ExcuteScalar("select ID from C_ProductGroup where Code = '" + TextUtils.ToString(row["F6"]) + "'"));

            item.ID = (int)pt.Insert(item);
            count++;
            row["ID"] = item.ID;

            DataRow[] drs = _dtData.Select("F1 like '" + stt + ".%'");
            foreach (DataRow rowC in drs)
            {
                decimal qtyC      = TextUtils.ToDecimal(rowC["F7"]);
                string  groupCode = TextUtils.ToString(rowC["F6"]);

                int groupID = TextUtils.ToInt(LibQLSX.ExcuteScalar("select ID from C_ProductGroup where Code = '" + groupCode + "'"));

                C_QuotationDetail_SXModel itemC = new C_QuotationDetail_SXModel();
                itemC.C_QuotationID    = Quotation.ID;
                itemC.ParentID         = item.ID;
                itemC.C_ProductGroupID = groupID;

                itemC.Qty       = qtyC;
                itemC.QtyT      = qtyC / item.Qty;
                itemC.PriceVT   = TextUtils.ToDecimal(rowC["F41"]);
                itemC.PriceVTTN = TextUtils.ToDecimal(row["F42"]);
                itemC.PriceVTPS = TextUtils.ToDecimal(row["F43"]);

                itemC.ModuleName  = TextUtils.ToString(rowC["F2"]);
                itemC.ModuleCode  = TextUtils.ToString(rowC["F3"]);
                itemC.Manufacture = TextUtils.ToString(rowC["F4"]);
                itemC.Origin      = TextUtils.ToString(rowC["F5"]);

                itemC.ID   = (int)pt.Insert(itemC);
                rowC["ID"] = itemC.ID;
                count++;
            }
        }
예제 #2
0
 protected C_QuotationDetail_SXFacade(C_QuotationDetail_SXModel model) : base(model)
 {
 }
예제 #3
0
        void calculateCost(C_QuotationDetail_SXModel item)
        {
            int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1

            if (item.C_ProductGroupID == 0)
            {
                C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", item.ID);
                item.TotalNC = 0;
                item.TotalPB = 0;
                C_QuotationDetail_SXBO.Instance.Update(item);
            }
            else
            {
                ArrayList arr = C_CostBO.Instance.FindByExpression(new Expression("IsUse", 1).And(new Expression("IsWithProject", 0)));
                DataTable dtCostProductGroup = LibQLSX.Select("select * from vC_CostProductGroupLinkNew where [C_ProductGroupID] = " + item.C_ProductGroupID);
                decimal   totalNC            = 0;
                decimal   totalPB            = 0;
                foreach (var c in arr)
                {
                    C_CostModel cost = (C_CostModel)c;
                    DataRow[]   drs  = dtCostProductGroup.Select("C_CostID = " + cost.ID);
                    if (drs.Length == 0)
                    {
                        continue;
                    }
                    C_CostQuotationItemLinkNewModel link = new C_CostQuotationItemLinkNewModel();

                    ArrayList arrLink = C_CostQuotationItemLinkNewBO.Instance.FindByExpression(new Expression("C_CostID", cost.ID).And(new Expression("C_QuotationDetail_SXID", item.ID)));
                    if (arrLink != null && arrLink.Count > 0)
                    {
                        link = (C_CostQuotationItemLinkNewModel)arrLink[0];
                    }

                    link.C_CostID = cost.ID;
                    link.C_QuotationDetail_SXID = item.ID;
                    link.IsDirect = cost.IsDirectCost;
                    if (link.IsDirect == 1)
                    {
                        #region Chi phí nhân công
                        if (link.ID == 0)
                        {
                            if (cost.Price == 0)
                            {
                                link.Price = 0;
                            }
                            else
                            {
                                link.PersonNumber = TextUtils.ToDecimal(drs[0]["PersonNumber"]);
                                int isFix = TextUtils.ToInt(drs[0]["IsFix"]);
                                if (isFix == 1)
                                {
                                    link.NumberDay = TextUtils.ToDecimal(drs[0]["NumberDay"]);
                                }
                                else
                                {
                                    link.NumberDay = TextUtils.ToDecimal(drs[0]["VtuPercent"]) * item.PriceVT / cost.Price;
                                }
                                link.TotalR = link.NumberDay * link.PersonNumber;
                                if (cost.ID == 61)//phòng thiết kế
                                {
                                    link.TotalR = link.NumberDay * link.PersonNumber * (1 + 0.3M * (item.Qty - 1)) / item.Qty;
                                    //link.Price = (link.NumberDay * link.PersonNumber) * (1 + 0.3M * (item.Qty - 1)) / item.Qty * cost.Price;
                                }
                                link.Price = link.TotalR * cost.Price;
                            }
                        }

                        totalNC += link.Price;
                        #endregion
                    }
                    else
                    {
                        #region Chi phí phân bổ
                        if (item.PriceHD > 0)
                        {
                            decimal valuePercent = TextUtils.ToDecimal(drs[0]["ValuePercentSX"]);

                            link.Price = valuePercent / 100 * item.PriceTPA;

                            if (link.C_CostID == costID)
                            {
                                link.Price = 0;
                            }
                            else
                            {
                                //link.Price = TextUtils.ToDecimal(row["ValuePercentSX"]) / 100 * item.PriceTPA;
                            }
                        }
                        #endregion
                    }

                    if (link.ID == 0)
                    {
                        C_CostQuotationItemLinkNewBO.Instance.Insert(link);
                    }
                    else
                    {
                        C_CostQuotationItemLinkNewBO.Instance.Update(link);
                    }

                    item.TotalNC = totalNC;
                    item.TotalPB = totalPB;
                    C_QuotationDetail_SXBO.Instance.Update(item);
                }
            }
        }
예제 #4
0
        private void treeData_KeyDown(object sender, KeyEventArgs e)
        {
            if (treeData.FocusedNode == null)
            {
                return;
            }
            if (e.KeyCode == Keys.Delete)
            {
                if (Quotation.IsApproved)
                {
                    return;
                }
                try
                {
                    string moduleCode = TextUtils.ToString(treeData.FocusedNode.GetValue(colModuleCode));
                    int    id         = TextUtils.ToInt(treeData.FocusedNode.GetValue(colDetailID));
                    if (C_QuotationDetail_SXBO.Instance.CheckExist("ParentID", id))
                    {
                        MessageBox.Show("Bạn không thể xóa được thiết bị chính khi nó còn chứa các thiết bị con.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        return;
                    }
                    if (MessageBox.Show("Bạn có chắc muốn xóa thiết bị [" + moduleCode + "]?", TextUtils.Caption,
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id);
                        if (item.ParentID > 0)
                        {
                            C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(item.ParentID);
                            itemP.PriceVT   -= item.PriceVT;
                            itemP.PriceVTLD -= item.PriceVTLD;
                            itemP.PriceVTPS -= item.PriceVTPS;
                            itemP.PriceVTTN -= item.PriceVTTN;
                            //itemP.PriceVT -= item.PriceVT;
                            itemP.PriceHD -= item.PriceHD;
                            C_QuotationDetail_SXBO.Instance.Update(itemP);
                        }

                        C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", id);
                        C_QuotationDetail_SXBO.Instance.Delete(id);

                        treeData.DeleteSelectedNodes();
                        if (item.ParentID == 0)
                        {
                            loadProduct();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            if (e.KeyCode == (Keys.C))
            {
                try
                {
                    string text = TextUtils.ToString(treeData.FocusedNode.GetValue(treeData.FocusedColumn));
                    Clipboard.SetText(text);
                }
                catch (Exception)
                {
                }
            }
        }
예제 #5
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool _isSaved = false;

            if (treeData.AllNodesCount == 0)
            {
                return;
            }
            treeData.ExpandAll();
            treeData.FocusedNode = null;

            DataTable dtSource = (DataTable)treeData.DataSource;

            DataRow[] drsVatTu = dtSource.Select("(PriceVT is null or PriceVT = 0) and (C_ProductGroupID > 0 and ParentID > 0)");
            if (drsVatTu.Length > 0)
            {
                MessageBox.Show("Bạn chưa nhập đủ VẬT TƯ SẢN XUẤT cho các hạng mục.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1

            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang xử lý..."))
            {
                #region Save item
                for (int i = 0; i < treeData.AllNodesCount; i++)
                {
                    int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID));
                    C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id);

                    item.ModuleCode = TextUtils.ToString(treeData.GetNodeByVisibleIndex(i).GetValue(colModuleCode));
                    item.ModuleName = TextUtils.ToString(treeData.GetNodeByVisibleIndex(i).GetValue(colModuleName));
                    item.PriceVTLD  = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTLD));
                    item.PriceVTPS  = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTPS));
                    item.PriceVT    = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTSX));
                    item.PriceVTTN  = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceVTTN));

                    item.PriceHD = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colPriceHD));

                    item.C_ProductGroupID = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colProductGroupID));
                    item.VAT  = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colVAT));
                    item.QtyT = TextUtils.ToDecimal(treeData.GetNodeByVisibleIndex(i).GetValue(colQtyT));

                    string sqlPB = "select sum(ValuePercentSX) from vC_CostProductGroupLinkNew where C_CostGroupNew_Code in ('N01','N08','N09','N11') and C_ProductGroupID = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID;
                    string sqlNC = "select sum(ValuePercentSX) from vC_CostProductGroupLinkNew where C_CostGroupNew_Code in ('N02','N03','N04','N07.02','N07.03') and C_ProductGroupID = " + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID;

                    decimal totalPercentCP_PB = TextUtils.ToDecimal(LibQLSX.ExcuteScalar(sqlPB)) / 100;
                    decimal totalPercentCP_NC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar(sqlNC)) / 100;

                    item.TotalPercentCP_NC = totalPercentCP_NC;
                    item.TotalPercentCP_PB = totalPercentCP_PB;

                    int parentID = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colParentID));
                    if (parentID == 0)
                    {
                        item.Qty = item.QtyT;
                    }
                    else
                    {
                        C_QuotationDetail_SXModel parent = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(parentID);
                        item.Qty = item.QtyT * parent.Qty;
                    }

                    item.UpdatedDate = DateTime.Now;
                    item.UpdatedBy   = Global.AppUserName;
                    C_QuotationDetail_SXBO.Instance.Update(item);
                }
                #endregion

                DataTable dtCostVT = LibQLSX.Select("select sum(isnull(Qty,0)*(isnull(PriceVT,0)+isnull(PriceVTTN,0)+isnull(PriceVTPS,0)+isnull(PriceVTLD,0)))"
                                                    + ", sum(isnull(Qty,0)*isnull(TotalPercentCP_NC,0))"
                                                    //+ ", sum(isnull(Qty,0)*isnull(TotalPercentCP_PB,0))"
                                                    + " from C_QuotationDetail_SX where (ParentID > 0 or (ParentID = 0 and C_ProductGroupID > 0)) and [C_QuotationID] = " + Quotation.ID);
                decimal totalAllVT           = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][0]) : 0;
                decimal totalAllPercentCP_NC = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][1]) : 0;
                //decimal totalAllPercentCP_PB = dtCostVT.Rows.Count > 0 ? TextUtils.ToDecimal(dtCostVT.Rows[0][2]) : 0;

                if (Quotation.StatusNC == 1)
                {
                    #region Tính nhân công theo % phân bổ
                    for (int i = 0; i < treeData.AllNodesCount; i++)
                    {
                        int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID));
                        C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id);

                        if (item.ParentID == 0 && item.C_ProductGroupID == 0)
                        {
                            continue;
                        }

                        decimal profitPercent = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select top 1 ProfitPercentSX from C_ProductGroup where ID = " + item.C_ProductGroupID)) / 100;

                        decimal percentPB = item.TotalPercentCP_NC + item.TotalPercentCP_PB;

                        decimal totalVT = item.PriceVT + item.PriceVTLD + item.PriceVTPS + item.PriceVTTN;

                        decimal tyle = (item.TotalPercentCP_NC + totalVT) / (totalAllPercentCP_NC + totalAllVT);
                        item.TotalDP    = Quotation.TotalDP_SX * tyle;      //dự phòng
                        item.TotalVC    = Quotation.TotalCPVCHB_C13 * tyle; //vận chuyển
                        item.TotalBX    = Quotation.TotalBXHB_C52 * tyle;   //bốc xếp
                        item.PriceDiLai = Quotation.TotalDiLai * tyle;      //Đi lại

                        item.TotalPB_DA = item.TotalDP + item.TotalVC + item.TotalBX + item.PriceDiLai;

                        item.PriceCP  = item.TotalPB_DA + totalVT;
                        item.PriceTPA = item.PriceCP * (1 + profitPercent) / (1 - percentPB * (1 + profitPercent));

                        item.TotalPB     = item.TotalPercentCP_PB / 100 * item.PriceTPA;
                        item.TotalNC     = item.TotalPercentCP_NC / 100 * item.PriceTPA;
                        item.TotalProfit = profitPercent * (item.PriceCP + (percentPB * item.PriceTPA));

                        C_QuotationDetail_SXBO.Instance.Update(item);

                        calculateCost_PB(item);
                    }
                    #endregion
                }
                else
                {
                    #region Tính nhân công theo công nhật

                    decimal totalAllNC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select sum(isnull(Qty,0) * isnull(Price,0)) from vC_CostQuotationItemLinkSX"
                                                                                  + " where IsDirect = 1 and [C_QuotationID] = " + Quotation.ID));

                    for (int i = 0; i < treeData.AllNodesCount; i++)
                    {
                        int id = TextUtils.ToInt(treeData.GetNodeByVisibleIndex(i).GetValue(colDetailID));
                        C_QuotationDetail_SXModel item = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(id);

                        if (item.ParentID == 0 && item.C_ProductGroupID == 0)
                        {
                            continue;
                        }

                        decimal profitPercent = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select top 1 ProfitPercentSX from C_ProductGroup where ID = " + item.C_ProductGroupID)) / 100;
                        decimal percentPB     = item.TotalPercentCP_PB;

                        decimal totalVT = item.PriceVT + item.PriceVTLD + item.PriceVTPS + item.PriceVTTN;
                        decimal totalNC = TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select sum(Price) from C_CostQuotationItemLinkNew where IsDirect = 1 and C_QuotationDetail_SXID = " + item.ID));

                        item.TotalNC    = totalNC;
                        item.TotalDP    = Quotation.TotalDP_SX * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT);      //dự phòng
                        item.TotalVC    = Quotation.TotalCPVCHB_C13 * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT); //vận chuyển
                        item.TotalBX    = Quotation.TotalBXHB_C52 * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT);   //bốc xếp
                        item.PriceDiLai = Quotation.TotalDiLai * (item.TotalNC + totalVT) / (totalAllNC + totalAllVT);      //Đi lại

                        item.TotalPB_DA = item.TotalDP + item.TotalVC + item.TotalBX;

                        item.PriceCP  = item.TotalNC + item.TotalPB_DA + totalVT;
                        item.PriceTPA = item.PriceCP * (1 + profitPercent) / (1 - percentPB * (1 + profitPercent));

                        item.TotalPB = percentPB * item.PriceTPA;
                        //item.TotalNC = item.TotalPercentCP_NC * item.PriceTPA;
                        item.TotalProfit = profitPercent * (item.PriceCP + (percentPB * item.PriceTPA));

                        C_QuotationDetail_SXBO.Instance.Update(item);

                        calculateCost_PB(item);
                    }
                    #endregion
                }

                #region Save parent
                ArrayList listParent = C_QuotationDetail_SXBO.Instance.FindByExpression(new Expression("ParentID", 0)
                                                                                        .And(new Expression("C_ProductGroupID", 0))
                                                                                        .And(new Expression("C_QuotationID", Quotation.ID)));

                if (listParent != null)
                {
                    foreach (var item in listParent)
                    {
                        C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)item;

                        DataTable dtChild = LibQLSX.Select("select PriceVTLD=Sum(QtyT*PriceVTLD),PriceVTPS=Sum(QtyT*PriceVTPS),PriceVT=Sum(QtyT*PriceVT),PriceVTTN=Sum(QtyT*PriceVTTN)"
                                                           + ",TotalNC=Sum(QtyT*TotalNC),TotalPB_DA=Sum(QtyT*TotalPB_DA),TotalPB=Sum(QtyT*TotalPB),PriceCP=Sum(QtyT*PriceCP),PriceTPA=Sum(QtyT*PriceTPA),PriceHD=Sum(QtyT*PriceHD)"
                                                           + ",TotalProfit=Sum(QtyT*TotalProfit)"
                                                           + ",TotalDP=Sum(QtyT*TotalDP),TotalVC=Sum(QtyT*TotalVC),TotalBX=Sum(QtyT*TotalBX) from C_QuotationDetail_SX where ParentID = " + itemP.ID);

                        itemP.PriceVTLD   = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTLD"]) : itemP.PriceVTLD;
                        itemP.PriceVTPS   = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTPS"]) : itemP.PriceVTPS;
                        itemP.PriceVT     = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVT"]) : itemP.PriceVT;
                        itemP.PriceVTTN   = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceVTTN"]) : itemP.PriceVTTN;
                        itemP.TotalNC     = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalNC"]) : itemP.TotalNC;
                        itemP.TotalPB_DA  = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalPB_DA"]) : itemP.TotalPB_DA;
                        itemP.TotalPB     = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalPB"]) : itemP.TotalPB;
                        itemP.PriceCP     = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceCP"]) : itemP.PriceCP;
                        itemP.PriceTPA    = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceTPA"]) : itemP.PriceTPA;
                        itemP.PriceHD     = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["PriceHD"]) : itemP.PriceHD;
                        itemP.TotalProfit = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalProfit"]) : itemP.TotalProfit;

                        itemP.TotalDP = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalDP"]) : itemP.TotalDP;
                        itemP.TotalVC = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalVC"]) : itemP.TotalVC;
                        itemP.TotalBX = dtChild.Rows.Count > 0 ? TextUtils.ToDecimal(dtChild.Rows[0]["TotalBX"]) : itemP.TotalBX;

                        C_QuotationDetail_SXBO.Instance.Update(itemP);
                    }
                }
                #endregion

                loadQuotationItem();
                _isSaved = true;
            }

            MessageBox.Show("Lưu trữ thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);

            if (_isSaved)
            {
                if (this.LoadDataChange != null)
                {
                    this.LoadDataChange(null, null);
                }
            }
        }
예제 #6
0
        private void btnAddModule_Click(object sender, EventArgs e)
        {
            #region Check
            if (txtModuleCode.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải thêm mã module!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtModuleName.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải thêm tên module!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtManufacture.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải thêm hãng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (txtOrigin.Text.Trim() == "")
            {
                MessageBox.Show("Bạn phải thêm xuất xứ!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (TextUtils.ToDecimal(txtPriceVTSX.EditValue) == 0 && cboProduct.EditValue != null)
            {
                MessageBox.Show("Bạn phải điền giá vật tư sản xuất!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (TextUtils.ToDecimal(txtQtyT.EditValue) == 0)
            {
                MessageBox.Show("Bạn phải điền số lượng!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (cboProductGroup.EditValue == null && cboProduct.EditValue != null)
            {
                MessageBox.Show("Bạn phải chọn một nhóm sản phẩm!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            #endregion

            C_QuotationDetail_SXModel item = new C_QuotationDetail_SXModel();

            item.C_QuotationID    = Quotation.ID;
            item.ParentID         = TextUtils.ToInt(cboProduct.EditValue);
            item.C_ProductGroupID = TextUtils.ToInt(cboProductGroup.EditValue);
            item.PriceVT          = TextUtils.ToDecimal(txtPriceVTSX.EditValue);
            item.PriceVTLD        = TextUtils.ToDecimal(txtPriceVTLD.EditValue);
            item.PriceVTPS        = TextUtils.ToDecimal(txtPriceVTPS.EditValue);
            item.PriceVTTN        = TextUtils.ToDecimal(txtPriceVTTN.EditValue);
            item.QtyT             = TextUtils.ToDecimal(txtQtyT.EditValue);
            item.Manufacture      = txtManufacture.Text.Trim();
            item.ModuleCode       = item.ModuleCodeHD = txtModuleCode.Text.Trim().ToUpper();
            item.ModuleName       = item.ModuleNameHD = txtModuleName.Text.Trim();
            item.Origin           = txtOrigin.Text.Trim();
            item.VAT = TextUtils.ToDecimal(txtVAT.EditValue);

            if (item.ParentID > 0)
            {
                item.Qty = TextUtils.ToDecimal(txtQtyT.EditValue) * TextUtils.ToDecimal(grvCboProduct.GetFocusedRowCellValue(colPQty));
            }
            else
            {
                item.Qty = item.QtyT = TextUtils.ToDecimal(txtQtyT.EditValue);
            }

            item.CreatedBy   = item.UpdatedBy = Global.AppUserName;
            item.CreatedDate = item.UpdatedDate = DateTime.Now;

            item.ID = (int)C_QuotationDetail_SXBO.Instance.Insert(item);

            if (item.ParentID > 0)
            {
                C_QuotationDetail_SXModel itemP = (C_QuotationDetail_SXModel)C_QuotationDetail_SXBO.Instance.FindByPK(item.ParentID);
                itemP.C_ProductGroupID = 0;
                itemP.PriceVT         += item.PriceVT;
                itemP.PriceVTLD       += item.PriceVTLD;
                itemP.PriceVTPS       += item.PriceVTPS;
                itemP.PriceVTTN       += item.PriceVTTN;
                C_QuotationDetail_SXBO.Instance.Update(itemP);
            }

            MessageBox.Show("Lưu trữ thành công.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);

            loadProduct();
            loadQuotationItem();

            txtPriceVTSX.EditValue = 0;
            txtQtyT.EditValue      = 1;
            txtModuleName.Text     = txtModuleCode.Text = "";
        }
예제 #7
0
        void calculateCost_PB(C_QuotationDetail_SXModel item)
        {
            int costID = (Quotation.DepartmentId == "D018" ? 73 : 72);//Phòng KD1->lấy ra chi phí nhân công KD2 không thì lấy chi phí nhân công KD1

            if (item.C_ProductGroupID == 0)
            {
                C_CostQuotationItemLinkNewBO.Instance.DeleteByAttribute("C_QuotationDetail_SXID", item.ID);
                item.TotalNC = 0;
                item.TotalPB = 0;
                C_QuotationDetail_KDBO.Instance.Update(item);
            }
            else
            {
                //ArrayList arr = C_CostBO.Instance.FindByExpression(new Expression("IsUse", 1));
                string sql = "";
                if (Quotation.StatusNC == 1)
                {
                    sql = "select *, ValuePercentSX = (select top 1 ValuePercentSX from vC_CostProductGroupLinkNew where C_CostID = a.ID and [C_ProductGroupID] = "
                          + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID + ") from vC_CostNew a where IsUse = 1 and IsDeleted = 0 and GroupCode in ('N01','N08','N09','N11','N02','N03','N04','N07.02','N07.03')";
                }
                else
                {
                    sql = "select *, ValuePercentSX = (select top 1 ValuePercentSX from vC_CostProductGroupLinkNew where C_CostID = a.ID and [C_ProductGroupID] = "
                          + item.C_ProductGroupID + " and [C_VersionID] = " + Quotation.C_VersionID + ") from vC_CostNew a where IsUse = 1 and IsDeleted = 0 and GroupCode in ('N01','N08','N09','N11')";
                }

                DataTable dtCost = LibQLSX.Select(sql);

                foreach (DataRow row in dtCost.Rows)
                {
                    string code = TextUtils.ToString(row["Code"]);
                    C_CostQuotationItemLinkNewModel link = new C_CostQuotationItemLinkNewModel();
                    ArrayList arrLink = C_CostQuotationItemLinkNewBO.Instance.FindByExpression(new Expression("C_CostID", TextUtils.ToInt(row["ID"]))
                                                                                               .And(new Expression("C_QuotationDetail_SXID", item.ID)));
                    if (arrLink != null && arrLink.Count > 0)
                    {
                        link = (C_CostQuotationItemLinkNewModel)arrLink[0];
                    }

                    link.C_CostID = TextUtils.ToInt(row["ID"]);
                    link.C_QuotationDetail_SXID = item.ID;
                    //if (link.C_CostID == costID)
                    //{
                    //    link.Price = 0;
                    //}
                    //else
                    //{
                    link.Price = TextUtils.ToDecimal(row["ValuePercentSX"]) / 100 * item.PriceTPA;
                    //}

                    if (link.ID == 0)
                    {
                        C_CostQuotationItemLinkNewBO.Instance.Insert(link);
                    }
                    else
                    {
                        C_CostQuotationItemLinkNewBO.Instance.Update(link);
                    }
                }
                C_QuotationDetail_KDBO.Instance.Update(item);
            }
        }
예제 #8
0
        void saveCN(ProcessTransaction pt, int count, DataRow row)
        {
            int     stt = TextUtils.ToInt(row["F1"]);
            decimal qty = TextUtils.ToDecimal(row["F7"]);

            C_QuotationDetail_SXModel item = new C_QuotationDetail_SXModel();

            item.C_QuotationID = Quotation.ID;
            item.ParentID      = 0;
            item.Qty           = item.QtyT = qty;
            item.PriceVT       = TextUtils.ToDecimal(row["F47"]);
            item.PriceVTTN     = TextUtils.ToDecimal(row["F48"]);
            item.PriceVTPS     = TextUtils.ToDecimal(row["F49"]);
            item.Manufacture   = TextUtils.ToString(row["F4"]);
            item.ModuleCode    = TextUtils.ToString(row["F3"]);
            item.ModuleName    = TextUtils.ToString(row["F2"]);
            item.Origin        = TextUtils.ToString(row["F5"]);

            item.C_ProductGroupID = TextUtils.ToInt(LibQLSX.ExcuteScalar("select ID from C_ProductGroup where Code = '" + TextUtils.ToString(row["F6"]) + "'"));

            item.ID = (int)pt.Insert(item);
            count++;
            row["ID"] = item.ID;

            DataRow[] drs = _dtData.Select("F1 like '" + stt + ".%'");
            foreach (DataRow rowC in drs)
            {
                decimal qtyC      = TextUtils.ToDecimal(rowC["F7"]);
                string  groupCode = TextUtils.ToString(rowC["F6"]);

                int groupID = TextUtils.ToInt(LibQLSX.ExcuteScalar("select ID from C_ProductGroup where Code = '" + groupCode + "'"));

                C_QuotationDetail_SXModel itemC = new C_QuotationDetail_SXModel();
                itemC.C_QuotationID    = Quotation.ID;
                itemC.ParentID         = item.ID;
                itemC.C_ProductGroupID = groupID;

                itemC.Qty       = qtyC;
                itemC.QtyT      = qtyC / item.Qty;
                itemC.PriceVT   = TextUtils.ToDecimal(rowC["F47"]);
                itemC.PriceVTTN = TextUtils.ToDecimal(row["F48"]);
                itemC.PriceVTPS = TextUtils.ToDecimal(row["F49"]);

                itemC.ModuleName  = TextUtils.ToString(rowC["F2"]);
                itemC.ModuleCode  = TextUtils.ToString(rowC["F3"]);
                itemC.Manufacture = TextUtils.ToString(rowC["F4"]);
                itemC.Origin      = TextUtils.ToString(rowC["F5"]);

                itemC.ID   = (int)pt.Insert(itemC);
                rowC["ID"] = itemC.ID;
                count++;

                #region Chi phí nhân công

                //Phòng thiết kê
                C_CostQuotationItemLinkNewModel linkP24 = new C_CostQuotationItemLinkNewModel();
                linkP24.C_CostID = Quotation.CreatedDepartmentID == 18 ? 101 : 61;
                linkP24.C_QuotationDetail_SXID = itemC.ID;
                linkP24.NumberDay    = TextUtils.ToDecimal(rowC["F10"]);
                linkP24.PersonNumber = TextUtils.ToDecimal(rowC["F9"]);
                linkP24.CostNCType   = TextUtils.ToString(rowC["F12"]);
                linkP24.TotalR       = linkP24.NumberDay * linkP24.PersonNumber;
                linkP24.Price        = linkP24.TotalR * TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select Price from C_CostNCType where C_CostID = "
                                                                                                 + linkP24.C_CostID + " and CostNCType = '" + linkP24.CostNCType + "'"));//pricePerDay;
                linkP24.IsDirect = 1;
                pt.Insert(linkP24);

                //Phòng SXLR
                C_CostQuotationItemLinkNewModel linkP07 = new C_CostQuotationItemLinkNewModel();
                linkP07.C_CostID = 64;
                linkP07.C_QuotationDetail_SXID = itemC.ID;
                linkP07.NumberDay    = TextUtils.ToDecimal(rowC["F16"]);
                linkP07.PersonNumber = TextUtils.ToDecimal(rowC["F15"]);
                linkP07.CostNCType   = TextUtils.ToString(rowC["F17"]);
                linkP07.TotalR       = linkP07.NumberDay * linkP07.PersonNumber;
                linkP07.Price        = linkP07.TotalR * TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select Price from C_CostNCType where C_CostID = "
                                                                                                 + linkP07.C_CostID + " and CostNCType = '" + linkP07.CostNCType + "'")); //pricePerDay;
                linkP07.IsDirect = 1;
                pt.Insert(linkP07);

                //Phòng Service
                C_CostQuotationItemLinkNewModel linkP12 = new C_CostQuotationItemLinkNewModel();
                linkP12.C_CostID = 63;
                linkP12.C_QuotationDetail_SXID = itemC.ID;
                linkP12.NumberDay    = TextUtils.ToDecimal(rowC["F21"]);
                linkP12.PersonNumber = TextUtils.ToDecimal(rowC["F20"]);
                linkP12.CostNCType   = TextUtils.ToString(rowC["F22"]);
                linkP12.TotalR       = linkP12.NumberDay * linkP12.PersonNumber;
                linkP12.Price        = linkP12.TotalR * TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select Price from C_CostNCType where C_CostID = "
                                                                                                 + linkP12.C_CostID + " and CostNCType = '" + linkP12.CostNCType + "'"));//pricePerDay;
                linkP12.IsDirect = 1;
                pt.Insert(linkP12);

                //Phòng PLD
                C_CostQuotationItemLinkNewModel linkPLD = new C_CostQuotationItemLinkNewModel();
                linkPLD.C_CostID = 103;
                linkPLD.C_QuotationDetail_SXID = itemC.ID;
                linkPLD.NumberDay    = TextUtils.ToDecimal(rowC["F30"]);
                linkPLD.PersonNumber = TextUtils.ToDecimal(rowC["F29"]);
                linkPLD.CostNCType   = TextUtils.ToString(rowC["F31"]);
                linkPLD.TotalR       = linkPLD.NumberDay * linkPLD.PersonNumber;
                linkPLD.Price        = linkPLD.TotalR * TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select Price from C_CostNCType where C_CostID = "
                                                                                                 + linkPLD.C_CostID + " and CostNCType = '" + linkPLD.CostNCType + "'"));//pricePerDay;
                linkPLD.IsDirect = 1;
                pt.Insert(linkPLD);

                //Phòng PCG
                C_CostQuotationItemLinkNewModel linkPCG = new C_CostQuotationItemLinkNewModel();
                linkPCG.C_CostID = 104;
                linkPCG.C_QuotationDetail_SXID = itemC.ID;
                linkPCG.NumberDay    = TextUtils.ToDecimal(rowC["F35"]);
                linkPCG.PersonNumber = TextUtils.ToDecimal(rowC["F34"]);
                linkPCG.CostNCType   = TextUtils.ToString(rowC["F36"]);
                linkPCG.TotalR       = linkPCG.NumberDay * linkPCG.PersonNumber;
                linkPCG.Price        = linkPCG.TotalR * TextUtils.ToDecimal(LibQLSX.ExcuteScalar("select Price from C_CostNCType where C_CostID = "
                                                                                                 + linkPCG.C_CostID + " and CostNCType = '" + linkPCG.CostNCType + "'"));//pricePerDay;
                linkPCG.IsDirect = 1;
                pt.Insert(linkPCG);
                #endregion
            }
        }