Exemple #1
0
        public static Creditnote Create(Customer Customer, List<CreditnoteLine> Lines, bool Simulate)
        {
            foreach (CreditnoteLine line in Lines)
            {
                if (!Item.Load (line.ItemId).Invoiced)
                {
                    // EXCEPTION: Exception.CreditnoteCreateItemNotInvoiced
                    throw new Exception (string.Format (Strings.Exception.CreditnoteCreateItemNotInvoiced));
                }
            }

            Creditnote result = new Creditnote (Customer, Lines);

            if (result.Total == 0)
            {
                // EXCEPTION: Exception.CreditnoteCreateEmpty
                throw new Exception (string.Format (Strings.Exception.CreditnoteCreateEmpty));
            }

            if (!Simulate)
            {
                foreach (CreditnoteLine line in result.Lines)
                {
                    Item item = Item.Load (line.ItemId);
                    item.Invoiced = false;
                    item.Save ();
                }
                result.Save ();
            }

            return result;
        }
Exemple #2
0
        public static Creditnote Load(Guid Id)
        {
            Creditnote result;

            try
            {
                Hashtable item = (Hashtable)SNDK.Convert.FromXmlDocument (SNDK.Convert.XmlNodeToXmlDocument (SorentoLib.Services.Datastore.Get<XmlDocument> (DatastoreAisle, Id.ToString ()).SelectSingleNode ("(//didius.creditnote)[1]")));
                result = new Creditnote ();

                result._id = new Guid ((string)item["id"]);

                if (item.ContainsKey ("createtimestamp"))
                {
                    result._createtimestamp = int.Parse ((string)item["createtimestamp"]);
                }

                if (item.ContainsKey ("updatetimestamp"))
                {
                    result._updatetimestamp = int.Parse ((string)item["updatetimestamp"]);
                }

                if (item.ContainsKey ("no"))
                {
                    result._no = int.Parse ((string)item["no"]);
                }

                if (item.ContainsKey ("customerid"))
                {
                    result._customerid = new Guid ((string)item["customerid"]);
                }

                if (item.ContainsKey ("total"))
                {
                    result._total = decimal.Parse ((string)item["total"]);
                }

                if (item.ContainsKey ("vat"))
                {
                    result._vat = decimal.Parse ((string)item["vat"]);
                }

                if (item.ContainsKey ("lines"))
                {
                    foreach (XmlDocument creditnoteline in (List<XmlDocument>)item["lines"])
                    {
                        result._lines.Add (CreditnoteLine.FromXmlDocument (creditnoteline));
                    }
                }
            }
            catch (Exception exception)
            {
                // LOG: LogDebug.ExceptionUnknown
                SorentoLib.Services.Logging.LogDebug (string.Format (SorentoLib.Strings.LogDebug.ExceptionUnknown, "DIDIUS.CREDITNOTE", exception.Message));

                // EXCEPTION: Excpetion.CreditnoteLoadGuid
                throw new Exception (string.Format (Strings.Exception.CreditnoteLoadGuid, Id));
            }

            return result;
        }
Exemple #3
0
        public static void MailCreditnote(Creditnote Creditnote, string PdfFilename)
        {
            Customer customer = Customer.Load (Creditnote.CustomerId);

            string _from = SorentoLib.Services.Settings.Get<string> (Enums.SettingsKey.didius_email_sender);

            string to = customer.Email;
            //			string to = "*****@*****.**";

            string subject = SorentoLib.Services.Settings.Get<string> (Enums.SettingsKey.didius_email_template_creditnote_subject);
            subject = ReplacePlaceholders (customer, subject);
            subject = ReplacePlaceholders (Creditnote, subject);

            string body = SorentoLib.Services.Settings.Get<string> (Enums.SettingsKey.didius_email_template_creditnote_body);
            body = ReplacePlaceholders (customer, body);
            body = ReplacePlaceholders (Creditnote, body);

            bool isbodyhtml = SorentoLib.Services.Settings.Get<bool> (Enums.SettingsKey.didius_email_template_creditnote_isbodyhtml);

            List<SorentoLib.Tools.Helpers.SendMailAttatchment> attatchments = new List<SorentoLib.Tools.Helpers.SendMailAttatchment> ();
            attatchments.Add (new SorentoLib.Tools.Helpers.SendMailAttatchment (SNDK.IO.FileToByteArray (PdfFilename), "kreditnota"+ Creditnote.No +".pdf", SNDK.IO.GetMimeType (PdfFilename)));

            SorentoLib.Tools.Helpers.SendMail (_from, to, subject, body, isbodyhtml, attatchments);
        }