Esempio n. 1
0
        //删除好友
        public void DeleteFriend(object sender, RoutedEventArgs e)
        {
            MessageBoxResult result = MessageBox.Show("删除该好友?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);

            if (MessageBoxResult.OK == result)
            {
                //进行删除好友的操作
                //将删除好友的信息发送给服务端,由服务端同时删除用户和好友的好友表中的对应ID
                JObject obj = new JObject();
                obj["Id"] = this.Id;
                String  str     = obj.ToString();
                MClient mClient = MClient.CreateInstance();
                mClient.SendDeleteFriend(str);
                //同时客户端本地将该好友从队列中删除
                SqliteConnect.DeleteFriendById(this.Id);
                //然后从好友队列中删除
                Application.Current.Dispatcher.Invoke(
                    new Action(() =>
                {
                    FriendListViewModel friendListViewModel = FriendListViewModel.CreateInstance();
                    FriendEntity.InGroupListDelete(friendListViewModel.friendGroups, this.Id);
                })
                    );
            }
        }
Esempio n. 2
0
        public MClientWindow(MClient mclient)
        {
            InitializeComponent();

            if (mclient != null)
            {
                _mclient = mclient;

                FirstNameTextBox.Text   = _mclient.FirstName;
                LastNameTextBox.Text    = _mclient.LastName;
                CarTypeTextBox.Text     = _mclient.CarType;
                LicensePNTextBox.Text   = _mclient.LicensePN;
                DescriptionTextBox.Text = _mclient.Description;
                ComboBox.Text           = _mclient.Status;

                CreateButton.Visibility = Visibility.Collapsed;
                UpdateButton.Visibility = Visibility.Visible;
                DeleteButton.Visibility = Visibility.Visible;
            }
            else
            {
                _mclient = new MClient();

                CreateButton.Visibility = Visibility.Visible;
                UpdateButton.Visibility = Visibility.Collapsed;
                DeleteButton.Visibility = Visibility.Collapsed;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Create EMail from Server (Request User)
        /// @ejb.interface-method view-type="both"
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="AD_User_ID"></param>
        /// <param name="toEMail"></param>
        /// <param name="toName"></param>
        /// <param name="subject"></param>
        /// <param name="message"></param>
        /// <returns>EMail or null</returns>
        public EMail CreateEMail(Ctx ctx, int AD_Client_ID, int AD_User_ID,
                                 String toEMail, String toName, String subject, String message)
        {
            MClient client = MClient.Get(ctx, AD_Client_ID);
            MUser   from   = new MUser(ctx, AD_User_ID, null);

            return(client.CreateEMail(from, toEMail, toName, subject, message));
        }
Esempio n. 4
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("M_Product_Category_ID=" + _M_Product_Category_ID
                     + ", Future=" + _SetFutureCostTo
                     + ", Standard=" + _SetStandardCostTo
                     + "; M_PriceList_Version_ID=" + _M_PriceList_Version_ID);
            if (_SetFutureCostTo == null)
            {
                _SetFutureCostTo = "";
            }
            if (_SetStandardCostTo == null)
            {
                _SetStandardCostTo = "";
            }
            //	Nothing to Do
            if (_SetFutureCostTo.Length == 0 && _SetStandardCostTo.Length == 0)
            {
                return("-");
            }
            //	PLV required
            if (_M_PriceList_Version_ID == 0 &&
                (_SetFutureCostTo.Equals(TO_PriceListLimit) || _SetStandardCostTo.Equals(TO_PriceListLimit)))
            {
                throw new Exception("@FillMandatory@  @M_PriceList_Version_ID@");
            }

            //	Validate Source
            if (!IsValid(_SetFutureCostTo))
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (Future) " + _SetFutureCostTo);
            }
            if (!IsValid(_SetStandardCostTo))
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (Standard) " + _SetStandardCostTo);
            }

            //	Prepare
            MClient client = MClient.Get(GetCtx());

            _ce = MCostElement.GetMaterialCostElement(client, MAcctSchema.COSTINGMETHOD_StandardCosting);
            if (_ce.Get_ID() == 0)
            {
                throw new Exception("@NotFound@ @M_CostElement_ID@ (StdCost)");
            }
            log.Config(_ce.ToString());
            _ass = MAcctSchema.GetClientAcctSchema(GetCtx(), client.GetAD_Client_ID());
            for (int i = 0; i < _ass.Length; i++)
            {
                CreateNew(_ass[i]);
            }
            Commit();

            //	Update Cost
            int counter = Update();

            return("#" + counter);
        }
Esempio n. 5
0
        public ActionResult Post([FromBody] MClient mclient)
        {
            var mclients = MClientRepository.GetMClients().ToList();

            mclient.Id = GetNewId(mclients);
            mclients.Add(mclient);

            MClientRepository.StoreMClient(mclients);
            return(Ok());
        }
Esempio n. 6
0
 private MClientViewModel()
 {
     boUserName = false;
     boPassWord = false;
     UserName   = "";
     PassWord   = "";
     isLand     = "false";
     Mclient    = MClient.CreateInstance("127.0.0.1", "5730");
     Mclient.ConnectServer();
 }
Esempio n. 7
0
        protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            if (requestCode != OauthRequestCode)
            {
                return;
            }

            _authInProgress = false;
            if (resultCode == Result.Ok && !MClient.IsConnecting && !MClient.IsConnected)
            {
                MClient.Connect();
            }
        }
        public ActionResult Delete(int id)
        {
            Shop.clientsManagment.Load();
            IMapper MClient = new MapperConfiguration(cfg => cfg.CreateMap <Client, MClient>()).CreateMapper();
            MClient b       = MClient.Map <Client, MClient>(Shop.clientsManagment.Find(x => x.Id == id).ElementAt(0));

            if (b != null)
            {
                Shop.clientsManagment.Delete(Shop.clientsManagment.Find(x => x.Id == id).ElementAt(0));
                Shop.clientsManagment.SaveChanges();
            }
            return(RedirectToAction("ProfileAdmin"));
        }
Esempio n. 9
0
        /// <summary>
        /// Server Base Class
        /// </summary>
        /// <param name="model"></param>
        /// <param name="initialNap">delay time running in sec</param>
        protected ViennaServer(ViennaProcessor model, int initialNap)

        {
            log    = VLogger.GetVLogger(this.GetType().FullName);
            _model = model;
            _ctx   = new Ctx(model.GetCtx().GetMap());
            if (_system == null)
            {
                _system = MSystem.Get(_ctx);
            }
            _client = MClient.Get(_ctx);
            _ctx.SetContext("#AD_Client_ID", _client.GetAD_Client_ID());
            _initialNap = initialNap;
        }
Esempio n. 10
0
        public override String LoadDocumentDetails()
        {
            costupdate = (MCostUpdate)GetPO();
            if (costupdate.GetM_Product_Category_ID() != 0)
            {
                mpc = MProductCategory.Get(GetCtx(), costupdate.GetM_Product_Category_ID());
            }

            _lines = LoadLines(costupdate);
            m_ce   = MCostElement.GetMaterialCostElement(MClient.Get(GetCtx()), X_C_AcctSchema.COSTINGMETHOD_StandardCosting);
            SetDateAcct(costupdate.GetDateAcct());
            SetDateDoc(costupdate.GetDateAcct());
            return(null);
        }
Esempio n. 11
0
        public static void UpdateMClient(MClient mclient)
        {
            using (var client = new HttpClient())
            {
                var rawData = JsonConvert.SerializeObject(mclient);
                var content = new StringContent(rawData, Encoding.UTF8, "application/json");

                var response = client.PutAsync(_url, content).Result;
                if (!response.IsSuccessStatusCode)
                {
                    throw new InvalidOperationException(response.StatusCode.ToString());
                }
            }
        }
Esempio n. 12
0
        /// <summary>
        //// get orders
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="display">Display Columns</param>
        /// <param name="column">Column Name</param>
        /// <param name="C_BPartner_ID">Business Partner</param>
        /// <param name="isReturnTrx">Return Transaction</param>
        /// <param name="OrgId">Organization</param>
        /// <param name="DropShip">Drop Shipment</param>
        /// <param name="IsSOTrx">Sales Transaction</param>
        /// <param name="forInvoices">For Invoice</param>
        /// <returns>List<VCreateFromGetCOrder>, List of Orders</returns>

        public List <VCreateFromGetCOrder> VCreateGetOrders(Ctx ctx, string display, string column, int C_BPartner_ID, bool isReturnTrx, int OrgId, bool DropShip, bool IsSOTrx, bool forInvoices)
        {
            List <VCreateFromGetCOrder> obj = new List <VCreateFromGetCOrder>();
            var     dis    = display;
            MClient tenant = MClient.Get(ctx);
            //Added O.ISSALESQUOTATION='N' in where condition(Sales quotation will not display in Order dropdown)
            StringBuilder sql = new StringBuilder("SELECT o.C_Order_ID," + display + " AS displays FROM C_Order o WHERE o.C_BPartner_ID=" + C_BPartner_ID + " AND o.IsSOTrx ='" + (IsSOTrx ? "Y" : "N")
                                                  + "' AND O.IsBlanketTrx = 'N' AND O.ISSALESQUOTATION='N' AND o.DocStatus IN ('CL','CO') ");

            if (OrgId > 0)
            {
                sql.Append("AND o.AD_Org_ID = " + OrgId);
            }

            // when create lines fom open from M_Inout then pick records from match po having m_inoutline is not null
            // when create lines fom open from M_Invoiceline then pick records from match po having m_invoiceline is not null
            sql.Append("AND o.IsReturnTrx='" + (isReturnTrx ? "Y" : "N") + "' AND o.IsDropShip='" + (DropShip ? "Y" : "N") + "'  AND o.C_Order_ID IN "
                       + @"(SELECT C_Order_ID FROM (SELECT ol.C_Order_ID,ol.C_OrderLine_ID,ol.QtyOrdered, 
            (SELECT SUM(m.qty) FROM m_matchPO m WHERE ol.C_OrderLine_ID=m.C_OrderLine_ID AND NVL(" + column + @", 0) != 0 AND m.ISACTIVE = 'Y' ) AS Qty,
            (SELECT SUM(IL.QtyInvoiced)  FROM C_INVOICELINE IL INNER JOIN C_Invoice I ON I.C_INVOICE_ID = IL.C_INVOICE_ID
            WHERE il.ISACTIVE = 'Y' AND I.DOCSTATUS NOT IN ('VO','RE') AND OL.C_ORDERLINE_ID  =IL.C_ORDERLINE_ID) AS QtyInvoiced FROM C_OrderLine ol ");

            // Get Orders based on the setting taken on Tenant to allow non item Product
            if (!forInvoices && tenant.Get_ColumnIndex("IsAllowNonItem") > 0 && !tenant.IsAllowNonItem())
            {
                sql.Append("INNER JOIN M_Product p ON ol.M_Product_ID = p.M_Product_ID AND p.ProductType = 'I'");
            }

            sql.Append(") GROUP BY C_Order_ID,C_OrderLine_ID,QtyOrdered "
                       + "HAVING QtyOrdered > SUM(nvl(Qty,0)) AND QtyOrdered > SUM(NVL(QtyInvoiced,0))) ORDER BY o.DateOrdered, o.DocumentNo");

            DataSet ds = DB.ExecuteDataset(sql.ToString());

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    VCreateFromGetCOrder objc = new VCreateFromGetCOrder();
                    objc.key   = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Order_ID"]);
                    objc.value = Util.GetValueOfString(ds.Tables[0].Rows[i]["displays"]);
                    obj.Add(objc);
                }
            }

            return(obj);
        }
Esempio n. 13
0
        }       //	prepare

        /// <summary>
        ///	Process - Test EMail
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            MClient client = MClient.Get(GetCtx(), _AD_Client_ID);

            log.Info(client.ToString());

            //	 Test Client Mail
            String clientTest = client.TestEMail();

            AddLog(0, null, null, client.GetName() + ": " + clientTest);

            //	Test Client DocumentDir
            if (!Ini.IsClient())
            {
                String documentDir = client.GetDocumentDir();
                if (documentDir == null || documentDir.Length == 0)
                {
                    documentDir = ".";
                }
                //File file = new File (documentDir);
                //System.IO.FileInfo  file= new System.IO.FileInfo(documentDir);
                System.IO.FileAttributes fil = new System.IO.FileAttributes();
                fil = System.IO.File.GetAttributes(documentDir);
                //if (file.Exists() && file.isDirectory())
                if ((fil & System.IO.FileAttributes.Directory) == System.IO.FileAttributes.Directory)
                {
                    AddLog(0, null, null, "Found Directory: " + client.GetDocumentDir());
                }
                else
                {
                    AddLog(0, null, null, "Not Found Directory: " + client.GetDocumentDir());
                }
            }

            MStore[] wstores = MStore.GetOfClient(client);
            for (int i = 0; i < wstores.Length; i++)
            {
                MStore store = wstores[i];
                String test  = store.TestEMail();
                AddLog(0, null, null, store.GetName() + ": " + test);
            }

            return(clientTest);
        } //	doIt
        /// <summary>
        /// Get Invoices
        /// </summary>
        /// <param name="ctx">Context</param>
        /// <param name="displays">Display Columns</param>
        /// <param name="cBPartnerId">Business Partner</param>
        /// <param name="isReturnTrxs">Return Transaction</param>
        /// <param name="IsDrop">Drop Shipemnt</param>
        /// <returns>List<VCreateFromGetCOrder>, List of Invoices</returns>
        public List <VCreateFromGetCOrder> GetInvoicesVCreate(Ctx ctx, string displays, int cBPartnerId, bool isReturnTrxs, bool IsDrop)
        {
            List <VCreateFromGetCOrder> obj = new List <VCreateFromGetCOrder>();
            MClient tenant = MClient.Get(ctx);

            StringBuilder sql = new StringBuilder("SELECT i.C_Invoice_ID," + displays + " AS displays FROM C_Invoice i INNER JOIN C_DocType d ON (i.C_DocType_ID = d.C_DocType_ID) "
                                                  // New column added to fill invoice which drop ship is true
                                                  + "WHERE i.C_BPartner_ID=" + cBPartnerId + " AND i.IsSOTrx='N' AND i.IsDropShip='" + (IsDrop ? "Y" : "N") + "' "
                                                  + "AND d.IsReturnTrx='" + (isReturnTrxs ? "Y" : "N") + "' AND i.DocStatus IN ('CL','CO') "
                                                  //Invoice vendor record created with Document Type having checkbox 'Treat As Discount' is true will not show on 'Create line From' on window : Return to Vendor.
                                                  + " AND i.TreatAsDiscount = 'N' "
                                                  + " AND i.C_Invoice_ID IN "
                                                  + "(SELECT C_Invoice_ID FROM (SELECT il.C_Invoice_ID,il.C_InvoiceLine_ID,il.QtyInvoiced,mi.Qty FROM C_InvoiceLine il "
                                                  + " LEFT OUTER JOIN M_MatchInv mi ON (il.C_InvoiceLine_ID=mi.C_InvoiceLine_ID) ");

            // Get Invoices based on the setting taken on Tenant to allow non item Product
            if (tenant.Get_ColumnIndex("IsAllowNonItem") > 0 && !tenant.IsAllowNonItem())
            {
                sql.Append(" INNER JOIN M_Product Mp On Mp.M_Product_ID = il.M_Product_ID WHERE Mp.ProductType = 'I' AND");
            }
            else
            {
                sql.Append(" LEFT JOIN M_Product Mp On Mp.M_Product_ID = il.M_Product_ID WHERE");
            }

            sql.Append(" (il.QtyInvoiced <> nvl(mi.Qty,0) AND mi.C_InvoiceLine_ID IS NOT NULL And Mp.Iscostadjustmentonlost = 'N') "
                       + " OR (NVL(Mi.Qty,0) = 0 AND Mi.C_Invoiceline_Id IS NOT NULL AND Mp.Iscostadjustmentonlost = 'Y') "
                       + " OR mi.C_InvoiceLine_ID IS NULL ) t GROUP BY C_Invoice_ID,C_InvoiceLine_ID,QtyInvoiced "
                       + " HAVING QtyInvoiced > SUM(nvl(Qty,0))) ORDER BY i.DateInvoiced, i.DocumentNo");

            DataSet ds = DB.ExecuteDataset(sql.ToString());

            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    VCreateFromGetCOrder objc = new VCreateFromGetCOrder();
                    objc.key   = Util.GetValueOfInt(ds.Tables[0].Rows[i]["C_Invoice_ID"]);
                    objc.value = Util.GetValueOfString(ds.Tables[0].Rows[i]["displays"]);
                    obj.Add(objc);
                }
            }
            return(obj);
        }
Esempio n. 15
0
        public ActionResult GetUserBILogin(string extraInfo, int recID)
        {
            Ctx           ctx    = Session["ctx"] as Ctx;
            BiPanelModel  model  = new BiPanelModel(ctx);
            List <string> result = model.GetUserBILogin();

            ViewBag.extraInfo = extraInfo;
            ViewBag.recID     = recID;
            int outvalue = 0;

            ViewBag.scriptt = null;

            //extraInfo=HttpUtility.UrlDecode(extraInfo);

            if (!int.TryParse(result[0], out outvalue))
            {
                string script = result[1] + "JsAPI?clientOrg=" + MClient.Get(ctx).GetValue() + "&" + extraInfo.Replace("@recordid", recID.ToString()) + "&token=" + result[0];
                ViewBag.scriptt = script;
            }
            else
            {
                if (outvalue == 1)
                {
                    ViewBag.Message = Msg.GetMsg(ctx, "VA037_BIToolMembership");
                }
                else if (outvalue == 2)
                {
                    ViewBag.Message = Msg.GetMsg(ctx, "VA037_BIUrlNotFound");
                }
                else if (outvalue == 3)
                {
                    ViewBag.Message = Msg.GetMsg(ctx, "VA037_NotBIUser");
                }
                else if (outvalue == 4)
                {
                    ViewBag.Message = Msg.GetMsg(ctx, "VA037_BICallingError");
                }
            }

            return(View());
            //}
            //return Json(JsonConvert.SerializeObject("4"), JsonRequestBehavior.AllowGet);
        }
Esempio n. 16
0
        }       //	prepare

        /// <summary>
        /// Perform Process.
        /// </summary>
        /// <returns> Message</returns>
        protected override String DoIt()
        {
            log.Info("R_MailText_ID=" + _R_MailText_ID);
            //	Mail Test
            _MailText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName());
            if (_MailText.GetR_MailText_ID() == 0)
            {
                throw new Exception("Not found @R_MailText_ID@=" + _R_MailText_ID);
            }
            //	Client Info
            _client = MClient.Get(GetCtx());
            if (_client.GetAD_Client_ID() == 0)
            {
                throw new Exception("Not found @AD_Client_ID@");
            }
            if (_client.GetSmtpHost() == null || _client.GetSmtpHost().Length == 0)
            {
                throw new Exception("No SMTP Host found");
            }
            //
            if (_AD_User_ID > 0)
            {
                _from = new MUser(GetCtx(), _AD_User_ID, Get_TrxName());
                if (_from.GetAD_User_ID() == 0)
                {
                    throw new Exception("No found @AD_User_ID@=" + _AD_User_ID);
                }
            }
            log.Fine("From " + _from);
            //long start = System.currentTimeMillis();
            long start = CommonFunctions.CurrentTimeMillis();

            if (_R_InterestArea_ID > 0)
            {
                SendInterestArea();
            }
            if (_C_BP_Group_ID > 0)
            {
                SendBPGroup();
            }
            return("@Created@=" + _counter + ", @Errors@=" + _errors + " - "
                   + (CommonFunctions.CurrentTimeMillis() - start) + "ms");
        }       //	doIt
        }       //	checkTableID

        /// <summary>
        /// Check/Initialize DocumentNo/Value Sequences for all Clients
        /// </summary>
        /// <param name="ctx">context</param>
        /// <param name="sp">server process or null</param>
        private static void CheckClientSequences(Ctx ctx, SvrProcess sp)
        {
            Trx trxName = null;

            if (sp != null)
            {
                trxName = sp.Get_Trx();
            }
            //	Sequence for DocumentNo/Value
            MClient[] clients = MClient.GetAll(ctx);
            for (int i = 0; i < clients.Length; i++)
            {
                MClient client = clients[i];
                if (!client.IsActive())
                {
                    continue;
                }
                MSequence.CheckClientSequences(ctx, client.GetAD_Client_ID(), trxName);
            } //	for all clients
        }     //	checkClientSequences
        }       //	prepare

        /// <summary>
        /// Perrform Process.
        /// </summary>
        /// <returns>Message</returns>
        protected override String DoIt()
        {
            MClient client = MClient.Get(GetCtx());

            if (client.IsMultiLingualDocument())
            {
                throw new Exception("@AD_Client_ID@: @IsMultiLingualDocument@");
            }
            //
            log.Info("" + client);
            String sql = "SELECT * FROM AD_Table "
                         + "WHERE TableName LIKE '%_Trl' AND TableName NOT LIKE 'AD%' "
                         + "ORDER BY TableName";
            //PreparedStatement pstmt = null;
            IDataReader idr = null;
            DataTable   dt  = null;

            try
            {
                //pstmt = DataBase.prepareStatement (sql, Get_Trx());
                //ResultSet rs = pstmt.executeQuery ();
                idr = DataBase.DB.ExecuteReader(sql, null, Get_Trx());
                dt  = new DataTable();
                dt.Load(idr);
                foreach (DataRow dr in dt.Rows)
                {
                    ProcessTable(new MTable(GetCtx(), dr, null), client.GetAD_Client_ID());
                }
            }
            catch (Exception e)
            {
                log.Log(Level.SEVERE, sql, e);
            }
            finally
            {
                dt = null;
                idr.Close();
            }
            return("OK");
        }       //	doIt
Esempio n. 19
0
        public ActionResult Put([FromBody] MClient mclient)
        {
            var mclients = MClientRepository.GetMClients().ToList();

            var mclientToUpdate = mclients.FirstOrDefault(p => p.Id == mclient.Id);

            if (mclientToUpdate != null)
            {
                mclientToUpdate.FirstName    = mclient.FirstName;
                mclientToUpdate.LastName     = mclient.LastName;
                mclientToUpdate.CarType      = mclient.CarType;
                mclientToUpdate.LicensePN    = mclient.LicensePN;
                mclientToUpdate.Description  = mclient.Description;
                mclientToUpdate.StartingDate = mclient.StartingDate;
                mclientToUpdate.Status       = mclient.Status;


                MClientRepository.StoreMClient(mclients);
                return(Ok());
            }

            return(NotFound());
        }
        /// <summary>
        /// Generates a url of report with parameters.
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="log"></param>
        /// <param name="pi"></param>
        /// <returns></returns>
        public string GetReportString(Ctx ctx, VLogger log, VAdvantage.ProcessEngine.ProcessInfo pi)
        {
            string        reportFilePath = "";
            List <string> result         = GetUserBILogin(ctx, log);
            int           outvalue       = 0;

            // check if return result returned by login is token or interger. If int value then show respective message.
            if (!int.TryParse(result[0], out outvalue))
            {
                object biRepID = DB.ExecuteScalar("SELECT VA039_BIREPORTID FROM AD_PRocess where AD_Process_ID=" + pi.GetAD_Process_ID());

                int rID = GetReportID(ctx, biRepID.ToString());

                string filters = GetReportParameters(ctx, rID, pi.GetAD_PInstance_ID(), pi);
                reportFilePath = result[1] + "JsAPI?clientOrg=" + MClient.Get(ctx).GetValue() + "&reportUUID=" + biRepID + "&token=" + result[0] + "&showFilters=false&showInfo=false" + filters;
            }
            else
            {
                if (outvalue == 1)
                {
                    reportFilePath = Msg.GetMsg(ctx, "VA037_BIToolMembership");
                }
                else if (outvalue == 2)
                {
                    reportFilePath = Msg.GetMsg(ctx, "VA037_BIUrlNotFound");
                }
                else if (outvalue == 3)
                {
                    reportFilePath = Msg.GetMsg(ctx, "VA037_NotBIUser");
                }
                else if (outvalue == 4)
                {
                    reportFilePath = Msg.GetMsg(ctx, "VA037_BICallingError");
                }
            }
            return(reportFilePath);
        }
Esempio n. 21
0
        /// <summary>
        /// Create Landed Cost accounting & Cost lines
        /// </summary>
        /// <param name="as1">accounting schema</param>
        /// <param name="fact">fact</param>
        /// <param name="line">document line</param>
        /// <param name="dr">DR entry (normal api)</param>
        /// <returns>true if landed costs were created</returns>
        private bool LandedCost(MAcctSchema as1, Fact fact, DocLine line, bool dr)
        {
            int C_InvoiceLine_ID = line.Get_ID();

            MLandedCostAllocation[] lcas = MLandedCostAllocation.GetOfInvoiceLine(
                GetCtx(), C_InvoiceLine_ID, GetTrx());
            if (lcas.Length == 0)
            {
                return(false);
            }

            //	Delete Old
            String sql = "DELETE FROM M_CostDetail WHERE C_InvoiceLine_ID=" + C_InvoiceLine_ID;
            int    no  = DataBase.DB.ExecuteQuery(sql, null, GetTrx());

            if (no != 0)
            {
                log.Config("CostDetail Deleted #" + no);
            }

            //	Calculate Total Base
            double totalBase = 0;

            for (int i = 0; i < lcas.Length; i++)
            {
                totalBase += Convert.ToDouble(lcas[i].GetBase());//.doubleValue();
            }
            //	Create New
            MInvoiceLine il = new MInvoiceLine(GetCtx(), C_InvoiceLine_ID, GetTrx());

            for (int i = 0; i < lcas.Length; i++)
            {
                MLandedCostAllocation lca = lcas[i];
                if (Env.Signum(lca.GetBase()) == 0)
                {
                    continue;
                }
                double percent = totalBase / Convert.ToDouble(lca.GetBase());
                String desc    = il.GetDescription();
                if (desc == null)
                {
                    desc = percent + "%";
                }
                else
                {
                    desc += " - " + percent + "%";
                }
                if (line.GetDescription() != null)
                {
                    desc += " - " + line.GetDescription();
                }

                //	Accounting
                ProductCost pc = new ProductCost(GetCtx(),
                                                 lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(), GetTrx());
                Decimal?drAmt = null;
                Decimal?crAmt = null;
                if (dr)
                {
                    drAmt = lca.GetAmt();
                }
                else
                {
                    crAmt = lca.GetAmt();
                }
                FactLine fl = fact.CreateLine(line, pc.GetAccount(ProductCost.ACCTTYPE_P_CostAdjustment, as1),
                                              GetC_Currency_ID(), drAmt, crAmt);
                fl.SetDescription(desc);

                //	Cost Detail - Convert to AcctCurrency
                Decimal allocationAmt = lca.GetAmt();
                if (GetC_Currency_ID() != as1.GetC_Currency_ID())
                {
                    allocationAmt = MConversionRate.Convert(GetCtx(), allocationAmt,
                                                            GetC_Currency_ID(), as1.GetC_Currency_ID(),
                                                            GetDateAcct(), GetC_ConversionType_ID(),
                                                            GetAD_Client_ID(), GetAD_Org_ID());
                }
                if (Env.Scale(allocationAmt) > as1.GetCostingPrecision())
                {
                    allocationAmt = Decimal.Round(allocationAmt, as1.GetCostingPrecision(), MidpointRounding.AwayFromZero);
                }
                if (!dr)
                {
                    allocationAmt = Decimal.Negate(allocationAmt);
                }
                if (!IsPosted())
                {
                    MCostDetail cd = new MCostDetail(as1, lca.GetAD_Org_ID(),
                                                     lca.GetM_Product_ID(), lca.GetM_AttributeSetInstance_ID(),
                                                     lca.GetM_CostElement_ID(),
                                                     allocationAmt, lca.GetQty(), //	Qty
                                                     desc, GetTrx());

                    cd.SetC_InvoiceLine_ID(C_InvoiceLine_ID);
                    bool ok = cd.Save();
                    if (ok && !cd.IsProcessed())
                    {
                        MClient client = MClient.Get(as1.GetCtx(), as1.GetAD_Client_ID());
                        if (client.IsCostImmediate())
                        {
                            cd.Process();
                        }
                    }
                }
            }

            log.Config("Created #" + lcas.Length);
            return(true);
        }
Esempio n. 22
0
        /// <summary>
        /// Send notice to user
        /// </summary>
        /// <param name="AD_User_ID">Id of user</param>
        /// <param name="NotificationType"> Notification type</param>
        /// <param name="client"> Tenant object</param>
        /// <param name="from"> From user notice</param>
        /// <param name="subject">Subject of notice.</param>
        /// <param name="message">Message to be sent to user</param>
        /// <param name="pdf"> Attachment</param>
        private void SendNoticeNow(int AD_User_ID, String NotificationType,
                                   MClient client, MUser from, String subject, String message, FileInfo pdf)
        {
            MUser to = MUser.Get(GetCtx(), AD_User_ID);

            if (NotificationType == null)
            {
                NotificationType = to.GetNotificationType();
            }
            //	Send Mail
            if (X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                VAdvantage.Model.MMailAttachment1 _mAttachment = new VAdvantage.Model.MMailAttachment1(GetCtx(), 0, null);
                _mAttachment.SetAD_Client_ID(GetCtx().GetAD_Client_ID());
                _mAttachment.SetAD_Org_ID(GetCtx().GetAD_Org_ID());
                _mAttachment.SetAD_Table_ID(MTable.Get_Table_ID(Table_Name));
                _mAttachment.IsActive();
                _mAttachment.SetMailAddress("");
                _mAttachment.SetAttachmentType("M");
                _mAttachment.SetRecord_ID(_req.GetR_Request_ID());
                _mAttachment.SetTextMsg(message);
                _mAttachment.SetTitle(subject);
                _mAttachment.SetMailAddress(to.GetEMail());

                if (from != null && !string.IsNullOrEmpty(from.GetEMail()))
                {
                    _mAttachment.SetMailAddressFrom(from.GetEMail());
                }
                else
                {
                    _mAttachment.SetMailAddressFrom(client.GetRequestEMail());
                }

                _mAttachment.NewRecord();

                if (client.SendEMail(from, to, subject, message.ToString(), pdf))
                {
                    _success++;
                    if (_emailTo.Length > 0)
                    {
                        _emailTo.Append(", ");
                    }
                    _emailTo.Append(to.GetEMail());
                    _mAttachment.SetIsMailSent(true);
                }
                else
                {
                    log.Warning("Failed: " + to);
                    _failure++;
                    NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                    _mAttachment.SetIsMailSent(false);
                }

                _mAttachment.Save();
            }

            //	Send Note
            if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) ||
                X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType))
            {
                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, AD_User_ID,
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, message.ToString(), Get_TrxName());
                if (note.Save())
                {
                    _notices++;
                }
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Send notice to users.
        /// </summary>
        /// <param name="list"> List of columns changed.</param>
        protected void SendNotices(List <String> list)
        {
            bool          isEmailSent = false;
            StringBuilder finalMsg    = new StringBuilder();

            finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NotificSent"));
            //	Subject
            if (mailText_ID == 0)
            {
                subject = Msg.Translate(GetCtx(), "R_Request_ID")
                          + " " + Msg.GetMsg(GetCtx(), "Updated", true) + ": " + _req.GetDocumentNo() + " (●" + MTable.Get_Table_ID(Table_Name) + "-" + _req.GetR_Request_ID() + "●) " + Msg.GetMsg(GetCtx(), "DoNotChange");
            }
            //	Message

            //		UpdatedBy: Joe
            int   UpdatedBy = GetCtx().GetAD_User_ID();
            MUser from      = MUser.Get(GetCtx(), UpdatedBy);

            FileInfo pdf = CreatePDF();

            log.Finer(message.ToString());

            //	Prepare sending Notice/Mail
            MClient client = MClient.Get(GetCtx(), GetAD_Client_ID());

            //	ReSet from if external
            if (from.GetEMailUser() == null || from.GetEMailUserPW() == null)
            {
                from = null;
            }
            _success = 0;
            _failure = 0;
            _notices = 0;

            /** List of users - aviod duplicates	*/
            List <int> userList = new List <int>();
            String     sql      = "SELECT u.AD_User_ID, u.NotificationType, u.EMail, u.Name, MAX(r.AD_Role_ID) "
                                  + "FROM RV_RequestUpdates_Only ru"
                                  + " INNER JOIN AD_User u ON (ru.AD_User_ID=u.AD_User_ID)"
                                  + " LEFT OUTER JOIN AD_User_Roles r ON (u.AD_User_ID=r.AD_User_ID) "
                                  + "WHERE ru.R_Request_ID= " + _req.GetR_Request_ID()
                                  + " GROUP BY u.AD_User_ID, u.NotificationType, u.EMail, u.Name";

            IDataReader idr = null;

            try
            {
                idr = DataBase.DB.ExecuteReader(sql, null, null);
                while (idr.Read())
                {
                    int    AD_User_ID       = Utility.Util.GetValueOfInt(idr[0]);
                    String NotificationType = Util.GetValueOfString(idr[1]); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = Util.GetValueOfString(idr[2]);// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = Util.GetValueOfString(idr[3]);//idr.GetString(3);
                    //	Role
                    int AD_Role_ID = Utility.Util.GetValueOfInt(idr[4]);
                    if (idr == null)
                    {
                        AD_Role_ID = -1;
                    }

                    //	Don't send mail to oneself
                    //		if (AD_User_ID == UpdatedBy)
                    //			continue;

                    //	No confidential to externals
                    if (AD_Role_ID == -1 &&
                        (_req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_Internal) ||
                         _req.GetConfidentialTypeEntry().Equals(X_R_Request.CONFIDENTIALTYPE_PrivateInformation)))
                    {
                        continue;
                    }

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }
                    if ((X_AD_User.NOTIFICATIONTYPE_EMail.Equals(NotificationType) ||
                         X_AD_User.NOTIFICATIONTYPE_EMailPlusNotice.Equals(NotificationType)) &&
                        (email == null || email.Length == 0))
                    {
                        if (AD_Role_ID >= 0)
                        {
                            NotificationType = X_AD_User.NOTIFICATIONTYPE_Notice;
                        }
                        else
                        {
                            log.Config("No EMail: " + Name);
                            continue;
                        }
                    }
                    if (X_AD_User.NOTIFICATIONTYPE_Notice.Equals(NotificationType) &&
                        AD_Role_ID >= 0)
                    {
                        log.Config("No internal User: "******"\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                idr.Close();
                // Notification For Role
                List <int> _users = SendRoleNotice();
                for (int i = 0; i < _users.Count; i++)
                {
                    MUser  user             = new MUser(GetCtx(), _users[i], null);
                    int    AD_User_ID       = user.GetAD_User_ID();
                    String NotificationType = user.GetNotificationType(); //idr.GetString(1);
                    if (NotificationType == null)
                    {
                        NotificationType = X_AD_User.NOTIFICATIONTYPE_EMail;
                    }
                    String email = user.GetEMail();// idr.GetString(2);

                    if (String.IsNullOrEmpty(email))
                    {
                        continue;
                    }

                    String Name = user.GetName(); //idr.GetString(3);
                                                  //	Role

                    if (X_AD_User.NOTIFICATIONTYPE_None.Equals(NotificationType))
                    {
                        log.Config("Opt out: " + Name);
                        continue;
                    }

                    //
                    SendNoticeNow(_users[i], NotificationType,
                                  client, from, subject, message.ToString(), pdf);
                    finalMsg.Append("\n").Append(user.GetName()).Append(".");
                    isEmailSent = true;
                }

                if (!isEmailSent)
                {
                    finalMsg.Clear();
                    finalMsg.Append(Msg.Translate(GetCtx(), "R_Request_ID") + ": " + _req.GetDocumentNo()).Append("\n").Append(Msg.Translate(GetCtx(), "R_NoNotificationSent"));
                }

                int   AD_Message_ID = 834;
                MNote note          = new MNote(GetCtx(), AD_Message_ID, GetCtx().GetAD_User_ID(),
                                                X_R_Request.Table_ID, _req.GetR_Request_ID(),
                                                subject, finalMsg.ToString(), Get_TrxName());
                if (note.Save())
                {
                    log.Log(Level.INFO, "ProcessFinished", "");
                }
            }
            catch (Exception e)
            {
                if (idr != null)
                {
                    idr.Close();
                }
                log.Log(Level.SEVERE, sql, e);
            }


            //	New Sales Rep (may happen if sent from beforeSave
            if (!userList.Contains(_req.GetSalesRep_ID()))
            {
                SendNoticeNow(_req.GetSalesRep_ID(), null,
                              client, from, subject, message.ToString(), pdf);
            }
        }
Esempio n. 24
0
 public MDomainModel(MQProperties qProperties)
 {
     mClient = new MClient(qProperties);
 }
Esempio n. 25
0
        public InfoColumn[] GetInfoColumns(VAdvantage.Utility.Ctx ctx)
        {
            if (s_productLayout != null)
            {
                return(s_productLayout);
            }
            //
            s_headerPriceList = Msg.Translate(ctx, "M_PriceList_Version_ID");
            s_headerWarehouse = Msg.Translate(ctx, "M_Warehouse_ID");
            //  Euro 13
            MClient client = MClient.Get(ctx);

            if ("FRIE".Equals(client.GetValue()))
            {
                InfoColumn[] frieLayout =
                {
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "M_Product_ID"),             "M_Product_ID",        true,           "p.M_Product_ID",                          DisplayType.ID).Seq(10),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "Name"),                     "Name",                true,           "p.Name",                                  DisplayType.String).Seq(20),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "QtyEntered"),               "QtyEntered",          false,          "0 as QtyEntered",                         DisplayType.Quantity).Seq(30),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "QtyAvailable"),             "QtyAvailable",        true,
                                   "bomQtyAvailable(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyAvailable",                                                                                      DisplayType.Quantity).Seq(40),
                    new InfoColumn(s_headerPriceList,                                                                                                                                         "M_PriceList_Version_ID",    true,                  "plv.Name",     DisplayType.Amount).Seq(50),
                    new InfoColumn(s_headerWarehouse,                                                                                                                                         "M_Warehouse_ID",            true,                  "w.Name",       DisplayType.String).Seq(60),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "PriceList"),                "PriceList",           true,
                                   "bomPriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList",                                                                                    DisplayType.Amount).Seq(70),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "PriceStd"),                 "PriceStd",            true,
                                   "bomPriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd",                                                                                      DisplayType.Amount).Seq(80),
                    new InfoColumn("Einzel MWSt",                                                                                                                                             "",                          true,
                                   "pr.PriceStd * 1.19",                                                                                                                                      DisplayType.Amount).Seq(90),
                    new InfoColumn("Einzel kompl",                                                                                                                                            "",                          true,
                                   "(pr.PriceStd+13) * 1.19",                                                                                                                                 DisplayType.Amount).Seq(100),
                    new InfoColumn("Satz kompl",                                                                                                                                              "",                          true,
                                   "((pr.PriceStd+13) * 1.19) * 4",                                                                                                                           DisplayType.Amount).Seq(110),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "QtyOnHand"),                "QtyOnHand",           true,
                                   "bomQtyOnHand(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyOnHand",                                                                                            DisplayType.Quantity).Seq(120),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "QtyReserved"),              "QtyReserved",         true,
                                   "bomQtyReserved(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyReserved",                                                                                        DisplayType.Quantity).Seq(130),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "QtyOrdered"),               "QtyOrdered",          true,
                                   "bomQtyOrdered(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyOrdered",                                                                                          DisplayType.Quantity).Seq(140),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "Discontinued").Substring(0,                    1), "Discontinued", true,
                                   "p.Discontinued",                                                                                                                                          DisplayType.YesNo).Seq(150),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "SalesMargin"),              "SalesMargin",         true,
                                   "bomPriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomPriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin",                               DisplayType.Amount).Seq(160),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "PriceLimit"),               "PriceLimit",          true,
                                   "bomPriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit",                                                                                  DisplayType.Amount).Seq(170),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "IsInstanceAttribute"),      "IsInstanceAttribute", true,
                                   "pa.IsInstanceAttribute",                                                                                                                                  DisplayType.YesNo).Seq(180),
                    new InfoColumn(Msg.Translate(ctx,                                                                                                                                         "GuranteeDays"),             "GuranteeDays",        true,           "Sysdate+p.GuaranteeDays as GuranteeDays", DisplayType.Date).Seq(190)
                    //new InfoColumn(Msg.Translate(ctx, "Quantity"), "0 as Quantity" , typeof(Boolean)).Seq(180)
                };
                INDEX_NAME       = 1;
                INDEX_PATTRIBUTE = frieLayout.Length - 1;       //	last item
                s_productLayout  = frieLayout;
                return(s_productLayout);
            }
            if (s_productLayout == null)
            {
                List <InfoColumn> list = new List <InfoColumn>();
                list.Add(new InfoColumn(Msg.Translate(ctx, "M_Product_ID"), "M_Product_ID", true, "p.M_Product_ID", DisplayType.ID).Seq(10));
                //list.Add(new InfoColumn(Msg.Translate(ctx, "SelectProduct"),"SelectProduct",true, "'N'", DisplayType.YesNo).Seq(20));
                list.Add(new InfoColumn(Msg.Translate(ctx, "Discontinued"), "Discontinued", true, "p.Discontinued", DisplayType.YesNo).Seq(30));
                list.Add(new InfoColumn(Msg.Translate(ctx, "Value"), "Value", true, "p.Value", DisplayType.String).Seq(40));
                list.Add(new InfoColumn(Msg.Translate(ctx, "Name"), "Name", true, "p.Name", DisplayType.String).Seq(50));
                list.Add(new InfoColumn(Msg.Translate(ctx, "QtyEntered"), "QtyEntered", false, "0 as QtyEntered", DisplayType.Quantity).Seq(80));
                list.Add(new InfoColumn(Msg.Translate(ctx, "QtyAvailable"), "QtyAvailable", true,
                                        "bomQtyAvailable(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyAvailable", DisplayType.Quantity).Seq(90));
                //}
                list.Add(new InfoColumn(s_headerPriceList, "PriceListVersion", true, "plv.Name as PriceListVersion", DisplayType.String).Seq(100));
                list.Add(new InfoColumn(s_headerWarehouse, "Warehouse", true, "w.Name as Warehouse", DisplayType.String).Seq(110));
                Tuple <String, String, String> mInfo = null;
                if (Env.HasModulePrefix("VAPRC_", out mInfo))
                {
                    Tuple <String, String, String> aInfo = null;
                    if (Env.HasModulePrefix("ED011_", out aInfo))
                    {
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceList"), "PriceList", true,
                                                "bomPriceListUom(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID,pr.C_UOM_ID) AS PriceList", DisplayType.Amount).Seq(120));
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceStd"), "PriceStd", true,
                                                "bomPriceStdUom(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID,pr.C_UOM_ID) AS PriceStd", DisplayType.Amount).Seq(130));
                    }
                    else
                    {
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceList"), "PriceList", true,
                                                "bomPriceListAttr(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID) AS PriceList", DisplayType.Amount).Seq(120));
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceStd"), "PriceStd", true,
                                                "bomPriceStdAttr(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID) AS PriceStd", DisplayType.Amount).Seq(130));
                    }
                }
                else
                {
                    list.Add(new InfoColumn(Msg.Translate(ctx, "PriceList"), "PriceList", true,
                                            "bomPriceList(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceList", DisplayType.Amount).Seq(120));
                    list.Add(new InfoColumn(Msg.Translate(ctx, "PriceStd"), "PriceStd", true,
                                            "bomPriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceStd", DisplayType.Amount).Seq(130));
                }

                list.Add(new InfoColumn(Msg.Translate(ctx, "QtyOnHand"), "QtyOnHand", true,
                                        "bomQtyOnHand(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyOnHand", DisplayType.Quantity).Seq(140));
                list.Add(new InfoColumn(Msg.Translate(ctx, "QtyReserved"), "QtyReserved", true,
                                        "bomQtyReserved(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyReserved", DisplayType.Quantity).Seq(150));
                list.Add(new InfoColumn(Msg.Translate(ctx, "QtyOrdered"), "QtyOrdered", true,
                                        "bomQtyOrdered(p.M_Product_ID,w.M_Warehouse_ID,0) AS QtyOrdered", DisplayType.Quantity).Seq(160));
                //}
                if (isConferm) //IsUnconfirmed())
                {
                    list.Add(new InfoColumn(Msg.Translate(ctx, "QtyUnconfirmed"), "QtyUnconfirmed", true,
                                            "(SELECT SUM(c.TargetQty) FROM M_InOutLineConfirm c INNER JOIN M_InOutLine il ON (c.M_InOutLine_ID=il.M_InOutLine_ID) INNER JOIN M_InOut i ON (il.M_InOut_ID=i.M_InOut_ID) WHERE c.Processed='N' AND i.M_Warehouse_ID=w.M_Warehouse_ID AND il.M_Product_ID=p.M_Product_ID) AS QtyUnconfirmed",
                                            DisplayType.Quantity).Seq(170));
                    list.Add(new InfoColumn(Msg.Translate(ctx, "QtyUnconfirmedMove"), "QtyUnconfirmedMove", true,
                                            "(SELECT SUM(c.TargetQty) FROM M_MovementLineConfirm c INNER JOIN M_MovementLine ml ON (c.M_MovementLine_ID=ml.M_MovementLine_ID) INNER JOIN M_Locator l ON (ml.M_LocatorTo_ID=l.M_Locator_ID) WHERE c.Processed='N' AND l.M_Warehouse_ID=w.M_Warehouse_ID AND ml.M_Product_ID=p.M_Product_ID) AS QtyUnconfirmedMove",
                                            DisplayType.Quantity).Seq(180));
                }
                if (Env.HasModulePrefix("VAPRC_", out mInfo))
                {
                    Tuple <String, String, String> aInfo = null;
                    if (Env.HasModulePrefix("ED011_", out aInfo))
                    {
                        list.Add(new InfoColumn(Msg.Translate(ctx, "SalesMargin"), "SalesMargin", true,
                                                "bomPriceStdUom(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID,pr.C_UOM_ID)-bomPriceLimitUom(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID,pr.C_UOM_ID) AS Margin",
                                                DisplayType.Amount).Seq(190));
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceLimit"), "PriceLimit", true,
                                                "bomPriceLimitUom(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID,pr.C_UOM_ID) AS PriceLimit", DisplayType.Amount).Seq(200));
                    }
                    else
                    {
                        list.Add(new InfoColumn(Msg.Translate(ctx, "SalesMargin"), "SalesMargin", true,
                                                "bomPriceStdAttr(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID)-bomPriceLimitAttr(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID) AS Margin",
                                                DisplayType.Amount).Seq(190));
                        list.Add(new InfoColumn(Msg.Translate(ctx, "PriceLimit"), "PriceLimit", true,
                                                "bomPriceLimitAttr(p.M_Product_ID, pr.M_PriceList_Version_ID,pr.M_AttriButeSetInstance_ID) AS PriceLimit", DisplayType.Amount).Seq(200));
                    }
                }
                else
                {
                    list.Add(new InfoColumn(Msg.Translate(ctx, "SalesMargin"), "SalesMargin", true,
                                            "bomPriceStd(p.M_Product_ID, pr.M_PriceList_Version_ID)-bomPriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS Margin", DisplayType.Amount).Seq(190));
                    list.Add(new InfoColumn(Msg.Translate(ctx, "PriceLimit"), "PriceLimit", true,
                                            "bomPriceLimit(p.M_Product_ID, pr.M_PriceList_Version_ID) AS PriceLimit", DisplayType.Amount).Seq(200));
                }
                list.Add(new InfoColumn(Msg.Translate(ctx, "IsInstanceAttribute"), "IsInstanceAttribute", true, "pa.IsInstanceAttribute", DisplayType.YesNo).Seq(210));
                list.Add(new InfoColumn(Msg.Translate(ctx, "GuranteeDays"), "GuranteeDays", true, "Sysdate+p.GuaranteeDays as GuranteeDays", DisplayType.Date).Seq(220));

                s_productLayout  = new InfoColumn[list.Count];
                s_productLayout  = list.ToArray();
                INDEX_NAME       = 3;
                INDEX_PATTRIBUTE = s_productLayout.Length - 1;  //	last item
            }
            return(s_productLayout);
        }
Esempio n. 26
0
        /// <summary>
        /// this method actually send mail, both static and dynamic.... and save info in MailAttachment....
        /// </summary>
        /// <param name="mails"></param>
        /// <param name="AD_User_ID"></param>
        /// <param name="AD_Client_ID"></param>
        /// <param name="AD_Org_ID"></param>
        /// <param name="attachment_ID"></param>
        /// <param name="fileNames"></param>
        /// <param name="fileNameForOpenFormat"></param>
        /// <param name="mailFormat"></param>
        /// <param name="notify"></param>
        /// <returns></returns>
        public string SendMailstart(List <NewMailMessage> mails, int AD_User_ID, int AD_Client_ID, int AD_Org_ID, int attachment_ID, List <string> fileNames, List <string> fileNameForOpenFormat, string mailFormat, bool notify, VAdvantage.Utility.EMail sendmails, List <int> documentID)
        {
            if (ctx == null)
            {
                return(null);
            }


            UserInformation userinfo = new UserInformation();
            SMTPConfig      config   = null;

            config = MailConfigMethod.GetUSmtpConfig(AD_User_ID, ctx);
            // var config = "";
            if (config == null)
            {
                MClient client = new MClient(ctx, AD_Client_ID, null);
                userinfo.Email = client.GetRequestEMail();
            }
            else
            {
                //Add user info to list..
                userinfo.Email = config.Email;
            }

            string[] to = null;
            string[] bc = null;

            string[] cc      = null;
            string   sub     = null;
            string   message = null;
            // int _record_id = 0;
            int _table_id = 0;

            string[] records = null;

            StringBuilder res = new StringBuilder();

            List <NewMailMessage> mail = mails.GetRange(0, mails.Count);

            for (int j = 0; j < mails.Count; j++)
            {
                VAdvantage.Utility.EMail sendmail = new VAdvantage.Utility.EMail(ctx, "", "", "", "", "", "",
                                                                                 true, false);

                to = mails[j].To.Split(';');
                bc = mails[j].Bcc;
                cc = mails[j].Cc.Split(';');
                StringBuilder bcctext = new StringBuilder();
                sub     = mails[j].Subject;
                message = mailFormat;
                if (mails[j].Body != null && mails[j].Body.Count > 0)
                {
                    List <string> keysss = mails[j].Body.Keys.ToList();
                    for (int q = 0; q < keysss.Count; q++)
                    {
                        message = message.Replace(keysss[q], mails[j].Body[keysss[q]]);
                    }
                }

                if (mails[j].Recordids != null)          //in case of static mail
                {
                    records = mails[j].Recordids.Split(',');
                }

                _table_id = Convert.ToInt32(mail[j].TableID);

                VAdvantage.Model.MMailAttachment1 _mAttachment = new VAdvantage.Model.MMailAttachment1(ctx, 0, null);



                if (sub == null || sub.Length == 0 || sub == "")
                {
                    sendmail.SetSubject(".");   //	pass validation
                }
                else
                {
                    sendmail.SetSubject(sub);
                }
                sendmail.SetMessageHTML(message);


                //used to get attachments uploaded by user.....
                if (mail[j].AttachmentFolder != null && mail[j].AttachmentFolder.Trim().Length > 0)
                {
                    string storedAttachmentPath = Path.Combine(HostingEnvironment.ApplicationPhysicalPath, AttachmentsUploadFolderName + "\\" + mail[j].AttachmentFolder);
                    if (Directory.Exists(storedAttachmentPath))
                    {
                        DirectoryInfo info = new DirectoryInfo(storedAttachmentPath);
                        if (info.GetFiles().Length > 0)
                        {
                            FileInfo[] files = info.GetFiles();

                            for (int a = 0; a < files.Length; a++)
                            {
                                if (fileNames.Contains(files[a].Name))
                                {
                                    FileStream   attachmentStream = File.OpenRead(files[a].FullName);
                                    BinaryReader binary           = new BinaryReader(attachmentStream);
                                    byte[]       buffer           = binary.ReadBytes((int)attachmentStream.Length);
                                    sendmail.AddAttachment(buffer, files[a].Name);
                                    _mAttachment.AddEntry(files[a].Name, buffer);
                                }
                            }
                        }
                    }
                }

                //used to get attachments of saved formats.. Currently not Supporting......
                if (attachment_ID > 0)
                {
                    VAdvantage.Model.MMailAttachment1 _mAttachment1 = new VAdvantage.Model.MMailAttachment1(ctx, attachment_ID, null);
                    if (_mAttachment1.GetEntryCount() > 0)
                    {
                        MAttachmentEntry[] entries = _mAttachment1.GetEntries();
                        for (int m = 0; m < entries.Count(); m++)
                        {
                            //if (fileNameForOpenFormat.Contains(entries[m].GetName()))
                            //{
                            byte[] buffer = entries[m].GetData();
                            sendmail.AddAttachment(buffer, entries[m].GetName());
                            _mAttachment.AddEntry(entries[m].GetName(), buffer);
                            //}
                        }
                    }
                }

                if (documentID != null || documentID.Count > 0)
                {
                    for (int i = 0; i < documentID.Count; i++)
                    {
                        try
                        {
                            int attachmentID = AttachmentID(documentID[i]);
                            //MAttachment objAttachment = new MAttachment(ctx, attachmentID, null, Common.GetPassword(), ctx.GetAD_Client_ID());
                            //objAttachment.Force = false;
                            ////objAttachment.AD_Client_ID = ctx.GetAD_Client_ID();
                            //byte[] fileByte = objAttachment.GetEntryData(0);
                            //string fileName = objAttachment.GetEntryName(0);
                            List <AttachedFileInfo> lstAttchments = GetBytes(ctx, attachmentID, "");
                            sendmail.AddAttachment(lstAttchments[0].FileBytes, lstAttchments[0].FileName);
                        }
                        catch (Exception ex)
                        {
                            res.Append(Msg.GetMsg(ctx, "VADMS_AttachmentNotFound for : " + documentID[i]) + ex.Message);
                        }
                    }
                }



                if (to != null)
                {
                    for (int i = 0; i < to.Length; i++)
                    {
                        if (to[i].ToString() != "")
                        {
                            sendmail.AddTo(to[i].ToString(), "");
                            // totext.Append(to[i].ToString() + ",");
                        }
                    }
                }

                if (bc != null)
                {
                    for (int i = 0; i < bc.Length; i++)
                    {
                        if (bc[i].ToString() != "")
                        {
                            sendmail.AddBcc(bc[i].ToString(), "");
                            bcctext.Append(bc[i].ToString() + ",");
                        }
                    }
                }

                if (cc != null)
                {
                    for (int i = 0; i < cc.Length; i++)
                    {
                        if (cc[i].ToString() != "")
                        {
                            sendmail.AddCc(cc[i].ToString(), "");
                            ///  cctext.Append(cc[i].ToString() + ",");
                        }
                    }
                }

                string res1 = sendmail.Send();

                if (records != null && records.Length > 0)//save entery in MailAttachment......
                {
                    for (int k = 0; k < records.Length; k++)
                    {
                        if (records[k] == null || records[k] == "" || records[k] == "0")
                        {
                            continue;
                        }
                        if (res1 != "OK")
                        {
                            _mAttachment.SetIsMailSent(false);
                        }
                        else
                        {
                            _mAttachment.SetIsMailSent(true);
                        }
                        int AD_Client_Id = ctx.GetAD_Client_ID();
                        int iOrgid       = ctx.GetAD_Org_ID();

                        _mAttachment.SetAD_Client_ID(AD_Client_Id);
                        _mAttachment.SetAD_Org_ID(iOrgid);
                        _mAttachment.SetAD_Table_ID(_table_id);
                        _mAttachment.IsActive();
                        _mAttachment.SetMailAddress(bcctext.ToString());
                        _mAttachment.SetAttachmentType("M");

                        _mAttachment.SetRecord_ID(Convert.ToInt32(records[k]));

                        _mAttachment.SetTextMsg(message);
                        _mAttachment.SetTitle(sub);

                        _mAttachment.SetMailAddressBcc(bcctext.ToString());
                        _mAttachment.SetMailAddress(mails[j].To);
                        _mAttachment.SetMailAddressCc(mails[j].Cc);
                        _mAttachment.SetMailAddressFrom(userinfo.Email);
                        if (_mAttachment.GetEntries().Length > 0)
                        {
                            _mAttachment.SetIsAttachment(true);
                        }
                        else
                        {
                            _mAttachment.SetIsAttachment(false);
                        }
                        _mAttachment.NewRecord();
                        if (_mAttachment.Save())
                        {
                        }
                        else
                        {
                            // log.SaveError(Msg.GetMsg(Env.GetCtx(), "RecordNotSaved"), "");
                        }
                    }
                }

                if (res1 != "OK")           // if mail not sent....
                {
                    if (res1 == "AuthenticationFailed.")
                    {
                        res.Append("AuthenticationFailed");
                        return(res.ToString());
                    }
                    else if (res1 == "ConfigurationIncompleteOrNotFound")
                    {
                        res.Append("ConfigurationIncompleteOrNotFound");
                        return(res.ToString());
                    }
                    else
                    {
                        res.Append(" " + Msg.GetMsg(ctx, "MailNotSentTo") + ": " + mails[j].To + " " + bcctext + " " + mails[j].Cc);
                    }
                }
                else
                {
                    {
                        if (!res.ToString().Contains("MailSent"))
                        {
                            res.Append("MailSent");
                        }
                    }
                }
                bcctext = null;
            }

            if (notify)             //  make an entry in Notice window.....
            {
                MNote note = new MNote(ctx, "SentMailNotice", AD_User_ID,
                                       AD_Client_ID, AD_Org_ID, null);
                //  Reference
                note.SetReference(ToString());  //	Document
                //	Text
                note.SetTextMsg(res.ToString());
                note.Save();
            }

            userinfo = null;
            cc       = null;
            bc       = null;
            to       = null; records = null;
            sub      = null; message = null;
            records  = null;
            return(res.ToString());
        }
Esempio n. 27
0
 public WorkflowProcessor(MWorkflowProcessor model)
     : base(model, 120)          //	2 minute dalay
 {
     m_model  = model;
     m_client = MClient.Get(model.GetCtx(), model.GetAD_Client_ID());
 }       //	WorkflowProcessor
Esempio n. 28
0
        /// <summary>
        /// Process
        /// </summary>
        /// <returns>info</returns>
        protected override String DoIt()
        {
            log.Info("C_DunningRun_ID=" + _C_DunningRun_ID + ",R_MailText_ID=" + _R_MailText_ID
                     + ", EmailPDF=" + _EMailPDF + ",IsOnlyIfBPBalance=" + _IsOnlyIfBPBalance);

            //	Need to have Template
            if (_EMailPDF && _R_MailText_ID == 0)
            {
                throw new Exception("@NotFound@: @R_MailText_ID@");
            }
            String    subject = "";
            MMailText mText   = null;

            if (_EMailPDF)
            {
                mText = new MMailText(GetCtx(), _R_MailText_ID, Get_TrxName());
                if (_EMailPDF && mText.Get_ID() == 0)
                {
                    throw new Exception("@NotFound@: @R_MailText_ID@ - " + _R_MailText_ID);
                }
                subject = mText.GetMailHeader();
            }
            //
            MDunningRun run = new MDunningRun(GetCtx(), _C_DunningRun_ID, Get_TrxName());

            if (run.Get_ID() == 0)
            {
                throw new Exception("@NotFound@: @C_DunningRun_ID@ - " + _C_DunningRun_ID);
            }
            //	Print Format on Dunning Level
            MDunningLevel level = new MDunningLevel(GetCtx(), run.GetC_DunningLevel_ID(), Get_TrxName());
            //MPrintFormat format = MPrintFormat.Get(GetCtx(), level.GetDunning_PrintFormat_ID(), false);

            MClient client = MClient.Get(GetCtx());

            int count  = 0;
            int errors = 0;

            MDunningRunEntry[] entries = run.GetEntries(false);
            for (int i = 0; i < entries.Length; i++)
            {
                MDunningRunEntry entry = entries[i];
                if (_IsOnlyIfBPBalance && Env.Signum(entry.GetAmt()) <= 0)
                {
                    continue;
                }
                //	To BPartner
                MBPartner bp = new MBPartner(GetCtx(), entry.GetC_BPartner_ID(), Get_TrxName());
                if (bp.Get_ID() == 0)
                {
                    AddLog(entry.Get_ID(), null, null, "@NotFound@: @C_BPartner_ID@ " + entry.GetC_BPartner_ID());
                    errors++;
                    continue;
                }
                //	To User
                MUser to = new MUser(GetCtx(), entry.GetAD_User_ID(), Get_TrxName());
                if (_EMailPDF)
                {
                    if (to.Get_ID() == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @AD_User_ID@ - " + bp.GetName());
                        errors++;
                        continue;
                    }
                    else if (to.GetEMail() == null || to.GetEMail().Length == 0)
                    {
                        AddLog(entry.Get_ID(), null, null, "@NotFound@: @EMail@ - " + to.GetName());
                        errors++;
                        continue;
                    }
                }
                //	BP Language
                //Language language =Language.getLoginLanguage();		//	Base Language
                Language language = Env.GetLoginLanguage(GetCtx());

                String tableName = "C_Dunning_Header_v";
                if (client.IsMultiLingualDocument())
                {
                    tableName += "t";
                    String AD_Language = bp.GetAD_Language();
                    if (AD_Language != null)
                    {
                        //language =language.getLanguage(AD_Language);
                    }
                }
                // format.SetLanguage(language);
                // format.SetTranslationLanguage(language);
                //	query
                Query query = new Query(tableName);
                query.AddRestriction("C_DunningRunEntry_ID", Query.EQUAL,
                                     entry.GetC_DunningRunEntry_ID());

                //	Engine
                //PrintInfo info = new PrintInfo(
                //    bp.GetName(),
                //    X_C_DunningRunEntry.Table_ID,
                //    entry.GetC_DunningRunEntry_ID(),
                //    entry.GetC_BPartner_ID());
                //info.SetDescription(bp.GetName() + ", Amt=" + entry.GetAmt());
                //ReportEngine re = new ReportEngine(GetCtx(), format, query, info);
                bool printed = false;
                if (_EMailPDF)
                {
                    EMail email = client.CreateEMail(to.GetEMail(), to.GetName(), null, null);
                    if (email == null || !email.IsValid())
                    {
                        AddLog(entry.Get_ID(), null, null,
                               "@RequestActionEMailError@ Invalid EMail: " + to);
                        errors++;
                        continue;
                    }
                    mText.SetUser(to);  //	variable context
                    mText.SetBPartner(bp);
                    mText.SetPO(entry);
                    String message = mText.GetMailText(true);
                    if (mText.IsHtml())
                    {
                        email.SetMessageHTML(mText.GetMailHeader(), message);
                    }
                    else
                    {
                        email.SetSubject(mText.GetMailHeader());
                        email.SetMessageText(message);
                    }
                    //
                    //File attachment = re.GetPDF(File.createTempFile("Dunning", ".pdf"));
                    //log.Fine(to + " - " + attachment);
                    //email.AddAttachment(attachment);
                    //
                    String    msg = email.Send();
                    MUserMail um  = new MUserMail(mText, entry.GetAD_User_ID(), email);
                    um.Save();
                    if (msg.Equals(EMail.SENT_OK))
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailOK@");
                        count++;
                        printed = true;
                    }
                    else
                    {
                        AddLog(entry.Get_ID(), null, null,
                               bp.GetName() + " @RequestActionEMailError@ " + msg);
                        errors++;
                    }
                }
                else
                {
                    //re.print();
                    count++;
                    printed = true;
                }
                if (printed)
                {
                    entry.SetProcessed(true);
                    entry.Save();
                    DunningLevelConsequences(level, entry);
                }
            }   //	for all dunning letters
            if (errors == 0)
            {
                run.SetProcessed(true);
                run.Save();
            }

            if (_EMailPDF)
            {
                return("@Sent@=" + count + " - @Errors@=" + errors);
            }
            return("@Printed@=" + count);
        }
        /// <summary>
        /// Perform Process.
        /// - Fill Table with QtyOnHand for Warehouse and Valuation Date
        /// - Perform Price Calculations
        /// </summary>
        /// <returns>message</returns>
        protected override String DoIt()
        {
            log.Info("M_Warehouse_ID=" + _M_Warehouse_ID
                     + ",C_Currency_ID=" + _C_Currency_ID
                     + ",DateValue=" + _DateValue
                     + ",M_PriceList_Version_ID=" + _M_PriceList_Version_ID
                     + ",M_CostElement_ID=" + _M_CostElement_ID);

            MWarehouse  wh  = MWarehouse.Get(GetCtx(), _M_Warehouse_ID);
            MClient     c   = MClient.Get(GetCtx(), wh.GetAD_Client_ID());
            MAcctSchema mas = c.GetAcctSchema();

            //  Delete (just to be sure)
            StringBuilder sql = new StringBuilder("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID=");

            sql.Append(GetAD_PInstance_ID());
            int        no          = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            MPInstance instance    = new MPInstance(GetCtx(), GetAD_PInstance_ID(), null);
            DateTime   Createddate = instance.GetCreated();

            Createddate = Createddate.AddHours(-1);

            string qry            = "select MAX(AD_PINSTANCE_ID) from AD_PINSTANCE WHERE AD_Process_ID=" + instance.GetAD_Process_ID() + " AND created<  TO_Date('" + Createddate.ToString("MM/dd/yyyy HH:mm:ss") + "', 'MM-DD-YYYY HH24:MI:SS')";
            int    MaxInstance_ID = Util.GetValueOfInt(DB.ExecuteScalar(qry, null, null));

            int no1 = DB.ExecuteQuery("DELETE FROM T_InventoryValue WHERE AD_PInstance_ID <=" + MaxInstance_ID);

            //	Insert Standard Costs
            sql = new StringBuilder("INSERT INTO T_InventoryValue "
                                    + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                                    + " AD_Client_ID, AD_Org_ID, CostStandard) "
                                    + "SELECT ").Append(GetAD_PInstance_ID())
                  .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
                          + " w.AD_Client_ID, w.AD_Org_ID, c.CurrentCostPrice "
                          + "FROM M_Warehouse w"
                          + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                          + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                          + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID))"
                          + " INNER JOIN M_CostElement ce ON (c.M_CostElement_ID=ce.M_CostElement_ID AND ce.CostingMethod='S' AND ce.CostElementType='M') "
                          + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID);
            int noInsertStd = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());

            log.Fine("Inserted Std=" + noInsertStd);
            if (noInsertStd == 0)
            {
                return("No Standard Costs found");
            }

            //	Insert addl Costs
            int noInsertCost = 0;

            if (_M_CostElement_ID != 0)
            {
                sql = new StringBuilder("INSERT INTO T_InventoryValue "
                                        + "(AD_PInstance_ID, M_Warehouse_ID, M_Product_ID, M_AttributeSetInstance_ID,"
                                        + " AD_Client_ID, AD_Org_ID, CostStandard, Cost, M_CostElement_ID) "
                                        + "SELECT ").Append(GetAD_PInstance_ID())
                      .Append(", w.M_Warehouse_ID, c.M_Product_ID, c.M_AttributeSetInstance_ID,"
                              + " w.AD_Client_ID, w.AD_Org_ID, 0, c.CurrentCostPrice, c.M_CostElement_ID "
                              + "FROM M_Warehouse w"
                              + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                              + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                              + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) "
                              + "WHERE w.M_Warehouse_ID=").Append(_M_Warehouse_ID)
                      .Append(" AND c.M_CostElement_ID=").Append(_M_CostElement_ID)
                      .Append(" AND NOT EXISTS (SELECT * FROM T_InventoryValue iv "
                              + "WHERE iv.AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                      .Append(" AND iv.M_Warehouse_ID=w.M_Warehouse_ID"
                              + " AND iv.M_Product_ID=c.M_Product_ID"
                              + " AND iv.M_AttributeSetInstance_ID=c.M_AttributeSetInstance_ID)");
                noInsertCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Inserted Cost=" + noInsertCost);
                //	Update Std Cost Records
                sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                        + "SET (Cost, M_CostElement_ID)="
                                        + "(SELECT c.CurrentCostPrice, c.M_CostElement_ID "
                                        + "FROM M_Warehouse w"
                                        + " INNER JOIN AD_ClientInfo ci ON (w.AD_Client_ID=ci.AD_Client_ID)"
                                        + " INNER JOIN C_AcctSchema acs ON (ci.C_AcctSchema1_ID=acs.C_AcctSchema_ID)"
                                        + " INNER JOIN M_Cost c ON (acs.C_AcctSchema_ID=c.C_AcctSchema_ID"
                                        + " AND acs.M_CostType_ID=c.M_CostType_ID AND c.AD_Org_ID IN (0, w.AD_Org_ID)) "
                                        + "WHERE c.M_CostElement_ID=" + _M_CostElement_ID
                                        + " AND w.M_Warehouse_ID=iv.M_Warehouse_ID"
                                        + " AND c.M_Product_ID=iv.M_Product_ID"
                                        + " AND c.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID AND rownum=1 AND w.m_warehouse_ID=" + _M_Warehouse_ID + ") "
                                        + "WHERE EXISTS (SELECT * FROM T_InventoryValue ivv "
                                        + "WHERE ivv.AD_PInstance_ID=" + GetAD_PInstance_ID()
                                        + " AND ivv.M_CostElement_ID IS NULL) AND iv.AD_PInstance_ID =" + GetAD_PInstance_ID());
                int noUpdatedCost = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Updated Cost=" + noUpdatedCost);
            }
            if ((noInsertStd + noInsertCost) == 0)
            {
                return("No Costs found");
            }

            //  Update Constants
            //  YYYY-MM-DD HH24:MI:SS.mmmm  JDBC Timestamp format
            // String myDate = _DateValue.ToString();
            sql = new StringBuilder("UPDATE T_InventoryValue SET ")
                  //.Append("DateValue=To_Date('").Append(myDate.Substring(0,10))
                  //.Append("23:59:59','MM-DD-YYYY HH24:MI:SS'),")
                  .Append("DateValue=").Append(GlobalVariable.TO_DATE(_DateValue, true)).Append(",")
                  .Append("M_PriceList_Version_ID=").Append(_M_PriceList_Version_ID).Append(",")
                  .Append("C_Currency_ID=").Append(_C_Currency_ID);
            if (_M_CostElement_ID != 0)
            {
                sql.Append(",").Append("M_CostElement_ID=").Append(_M_CostElement_ID);
            }
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Constants=" + no);

            //  Get current QtyOnHand with ASI
            sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = "
                                    + "(SELECT SUM(QtyOnHand) FROM M_Storage s"
                                    + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
                                    + "WHERE iv.M_Product_ID=s.M_Product_ID"
                                    + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID"
                                    + " AND iv.M_AttributeSetInstance_ID=s.M_AttributeSetInstance_ID) "
                                    + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                  .Append(" AND iv.M_AttributeSetInstance_ID<>0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("QtHand with ASI=" + no);
            //  Get current QtyOnHand without ASI
            sql = new StringBuilder("UPDATE T_InventoryValue iv SET QtyOnHand = "
                                    + "(SELECT SUM(QtyOnHand) FROM M_Storage s"
                                    + " INNER JOIN M_Locator l ON (l.M_Locator_ID=s.M_Locator_ID) "
                                    + "WHERE iv.M_Product_ID=s.M_Product_ID"
                                    + " AND iv.M_Warehouse_ID=l.M_Warehouse_ID) "
                                    + "WHERE AD_PInstance_ID=").Append(GetAD_PInstance_ID())
                  .Append(" AND iv.M_AttributeSetInstance_ID=0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("QtHand w/o ASI=" + no);

            //  Adjust for Valuation Date
            sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                    + "SET QtyOnHand="
                                    + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
                                    + "FROM M_Transaction t"
                                    + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
                                    + "WHERE t.M_Product_ID=iv.M_Product_ID"
                                    + " AND t.M_AttributeSetInstance_ID=iv.M_AttributeSetInstance_ID"
                                    + " AND t.MovementDate > iv.DateValue"
                                    + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
                                    + "WHERE iv.M_AttributeSetInstance_ID<>0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Update with ASI=" + no);
            //
            sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                    + "SET QtyOnHand="
                                    + "(SELECT iv.QtyOnHand - NVL(SUM(t.MovementQty), 0) "
                                    + "FROM M_Transaction t"
                                    + " INNER JOIN M_Locator l ON (t.M_Locator_ID=l.M_Locator_ID) "
                                    + "WHERE t.M_Product_ID=iv.M_Product_ID"
                                    + " AND t.MovementDate > iv.DateValue"
                                    + " AND l.M_Warehouse_ID=iv.M_Warehouse_ID) "
                                    + "WHERE iv.M_AttributeSetInstance_ID=0");
            no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
            log.Fine("Update w/o ASI=" + no);

            //  Delete Records w/o OnHand Qty
            sql = new StringBuilder("DELETE FROM T_InventoryValue "
                                    + "WHERE (QtyOnHand=0 OR QtyOnHand IS NULL) AND AD_PInstance_ID=").Append(GetAD_PInstance_ID());
            int noQty = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());

            log.Fine("NoQty Deleted=" + noQty);

            //  Update Prices
            no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue iv "
                                          + "SET PricePO = "
                                          + "(SELECT MAX(currencyConvert (po.PriceList,po.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, po.AD_Client_ID,po.AD_Org_ID))"
                                          + " FROM M_Product_PO po WHERE po.M_Product_ID=iv.M_Product_ID"
                                          + " AND po.IsCurrentVendor='Y'), "
                                          + "PriceList = "
                                          + "(SELECT currencyConvert(pp.PriceList,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
                                          + "PriceStd = "
                                          + "(SELECT currencyConvert(pp.PriceStd,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID), "
                                          + "PriceLimit = "
                                          + "(SELECT currencyConvert(pp.PriceLimit,pl.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, pl.AD_Client_ID,pl.AD_Org_ID)"
                                          + " FROM M_PriceList pl, M_PriceList_Version plv, M_ProductPrice pp"
                                          + " WHERE pp.M_Product_ID=iv.M_Product_ID AND pp.M_PriceList_Version_ID=iv.M_PriceList_Version_ID"
                                          + " AND pp.M_PriceList_Version_ID=plv.M_PriceList_Version_ID"
                                          + " AND plv.M_PriceList_ID=pl.M_PriceList_ID)"
                                          , null, Get_TrxName());
            String msg = "";

            if (no == 0)
            {
                msg = "No Prices";
            }

            //	Convert if different Currency
            if (mas.GetC_Currency_ID() != _C_Currency_ID)
            {
                sql = new StringBuilder("UPDATE T_InventoryValue iv "
                                        + "SET CostStandard= "
                                        + "(SELECT currencyConvert(iv.CostStandard,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
                                        + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + "),"
                                        + "	Cost= "
                                        + "(SELECT currencyConvert(iv.Cost,acs.C_Currency_ID,iv.C_Currency_ID,iv.DateValue,null, iv.AD_Client_ID,iv.AD_Org_ID) "
                                        + "FROM C_AcctSchema acs WHERE acs.C_AcctSchema_ID=" + mas.GetC_AcctSchema_ID() + ") "
                                        + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID());
                no = DataBase.DB.ExecuteQuery(sql.ToString(), null, Get_TrxName());
                log.Fine("Convered=" + no);
            }

            //  Update Values
            no = DataBase.DB.ExecuteQuery("UPDATE T_InventoryValue SET "
                                          + "PricePOAmt = QtyOnHand * PricePO, "
                                          + "PriceListAmt = QtyOnHand * PriceList, "
                                          + "PriceStdAmt = QtyOnHand * PriceStd, "
                                          + "PriceLimitAmt = QtyOnHand * PriceLimit, "
                                          + "CostStandardAmt = QtyOnHand * CostStandard, "
                                          + "CostAmt = QtyOnHand * Cost "
                                          + "WHERE AD_PInstance_ID=" + GetAD_PInstance_ID(), null, Get_TrxName());
            log.Fine("Calculation=" + no);
            //
            return(msg);
        }
Esempio n. 30
0
        }       //	sendAlerts

        private int SendEmail(MWFActivity activity, String AD_Message, bool toProcess, bool toSupervisor)
        {
            if (m_client == null || m_client.GetAD_Client_ID() != activity.GetAD_Client_ID())
            {
                m_client = MClient.Get(GetCtx(), activity.GetAD_Client_ID());
            }

            MWFProcess process = new MWFProcess(GetCtx(), activity.GetAD_WF_Process_ID(), null);

            String subjectVar = activity.GetNode().GetName();
            String message    = activity.GetTextMsg();

            if (message == null || message.Length == 0)
            {
                message = process.GetTextMsg();
            }
            FileInfo pdf = null;
            PO       po  = activity.GetPO();

            if (po is DocAction)
            {
                message = ((DocAction)po).GetDocumentInfo() + "\n" + message;
                pdf     = ((DocAction)po).CreatePDF();
            }

            //  Inactivity Alert: Workflow Activity {0}
            String subject = Msg.GetMsg(m_client.GetAD_Language(), AD_Message,
                                        new Object[] { subjectVar });

            //	Prevent duplicates
            List <int> list    = new List <int>();
            int        counter = 0;

            //	To Activity Owner
            if (m_client.SendEMail(activity.GetAD_User_ID(), subject, message, pdf))
            {
                counter++;
            }
            list.Add(activity.GetAD_User_ID());

            //	To Process Owner
            if (toProcess &&
                process.GetAD_User_ID() != activity.GetAD_User_ID())
            {
                if (m_client.SendEMail(process.GetAD_User_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(process.GetAD_User_ID());
            }

            //	To Activity Responsible
            MWFResponsible responsible = MWFResponsible.Get(GetCtx(), activity.GetAD_WF_Responsible_ID());

            counter += sendAlertToResponsible(responsible, list, process, subject, message, pdf);

            //	To Process Responsible
            if (toProcess &&
                process.GetAD_WF_Responsible_ID() != activity.GetAD_WF_Responsible_ID())
            {
                responsible = MWFResponsible.Get(GetCtx(), process.GetAD_WF_Responsible_ID());
                counter    += sendAlertToResponsible(responsible, list, process, subject, message, pdf);
            }

            //	Processor SuperVisor
            if (toSupervisor && m_model.GetSupervisor_ID() != 0 &&
                !list.Contains(m_model.GetSupervisor_ID()))
            {
                if (m_client.SendEMail(m_model.GetSupervisor_ID(), subject, message, pdf))
                {
                    counter++;
                }
                list.Add(m_model.GetSupervisor_ID());
            }

            return(counter);
        }   //  sendAlert