Пример #1
0
        /// <summary>
        /// ******************Important!*****************
        /// </summary>
        /// <param name="model"></param>
        /// <param name="epiSession"></param>
        /// <param name="IsSucces"></param>
        /// <param name="msgError"></param>
        /// <returns></returns>
        public bool GetNewRcv(RecieptHeadModel head, List<ReceiptDetailModel> model, Epicor.Mfg.Core.Session epiSession, out bool IsSucces, out string msgError)
        {
            msgError = "";
            ReceiptDataSet dsReceipt = new ReceiptDataSet();
            try
            {
                Receipt myReceipt = new Receipt(epiSession.ConnectionPool);
                myReceipt.ValidateMRPONum(head.PONum, head.VendorNum, out msgError);

                #region PO no error.

                if (string.IsNullOrEmpty(msgError))
                {
                    /*This OK*/
                    myReceipt.GetNewRcvHead(dsReceipt, head.VendorNum, "");

                    /*Fix for testing
                    myReceipt.GetNewRcvHead(dsReceipt, 5, "");
                    */

                    DataRow drReceipt = dsReceipt.Tables[0].Rows[0];
                    drReceipt.BeginEdit();
                    string PackSlip = head.StoreInNum + "-RCV";

                    /* This OK */
                    drReceipt["VendorNum"] = head.VendorNum;
                    drReceipt["PackSlip"] = PackSlip;
                    drReceipt["ReceiptDate"] = DateTime.Now;
                    drReceipt["ReceivePerson"] = epiSession.UserID;
                    drReceipt["ShipViaCode"] = "UC02";
                    drReceipt["PONum"] = head.PONum;

                    /*Fix for testing
                    drReceipt["VendorNum"] = 5;
                    drReceipt["PackSlip"] = "IN00002-5";
                    drReceipt["ReceiptDate"] = DateTime.Now;
                    drReceipt["ReceivePerson"] = "manager";
                    drReceipt["ShipViaCode"] = "UC02";
                    drReceipt["PONum"] = 272;
                    */

                    drReceipt.EndEdit();
                    myReceipt.Update(dsReceipt);

                    //myReceipt.CreateMassReceipts(model.VendorNum, "", model.StoreInNum, 0, model.PONum.ToString(), dsReceipt);
                    myReceipt.CreateMassReceipts(head.VendorNum, "", PackSlip, 0, head.PONum.ToString(), dsReceipt);

                    myReceipt.ReceiveAll(dsReceipt);
                    int i = 0;
                    foreach (DataRow dr in dsReceipt.Tables["RcvDtl"].Rows)
                    {
                        //myReceipt.GetNewRcvDtl(dsReceipt, model.VendorNum, "", model.StoreInNum);
                        //DataRow drDtl = dsReceipt.Tables["RcvDtl"].Rows[i];
                        //myReceipt.GetDtlQtyInfo(dsReceipt, model.VendorNum, "", model.StoreInNum, dr["PackLine"].GetInt(), 1, "KG", "", out msgError);
                        ReceiptDetailModel result = model.Where<ReceiptDetailModel>(p => p.PONum.ToString().Equals(dr["PONum"].ToString())
                                                                && p.POLine.ToString().Equals(dr["POLine"].ToString())).Single<ReceiptDetailModel>();
                        dr.BeginEdit();
                        dr["OurQty"] = result.Weight;
                        dr["OurUnitCost"] = 1;
                        //dr["VendorQty"] = result.Weight;
                        dr["ReceivedComplete"] = false;
                        dr["DocUnitCost"] = 20;  //ถ้าเป็น PO Sample จะเป็น 0 (Else result.UnitPrice)
                        dr["POTransValue"] = 20;
                        dr["ExtTransValue"] = 20;
                        dr["InputOurQty"] = result.Weight;
                        dr["Number01"] = result.Weight;   //Weight
                        dr["Received"] = true;
                        dr.EndEdit();

                        i++;
                    }
                    myReceipt.Update(dsReceipt);
                    myReceipt.ReceiveAllLines(true, dsReceipt);

                    //myReceipt.CommitRcvDtl(model.VendorNum, "", model.StoreInNum, dsReceipt);
                    IsSucces = true;
                    msgError = "";
                    return IsSucces;
                }

                #endregion PO no error.

                IsSucces = false;
                return IsSucces;
            }
            catch (Exception ex)
            {
                IsSucces = false;
                msgError = ex.Message;
                return IsSucces;
            }
        }