public void importWriteOffs(bool importClosedMatters) { DataTable TableWUD = new DataTable("WUD"); string sSelect = ""; int nInvID = 0; sSelect = "SELECT * from WUD where amount <> 0.0000"; ReadAMTable(ref TableWUD, sSelect); if (importClosedMatters) { PLBilling.m_bAllowEntOnClosedMtr = true; PLTimeEntry.m_bAllowEntOnClosedMtr = true; PLExpense.m_bAllowEntOnClosedMtr = true; PLGBEnt.m_bAllowEntOnClosedMtr = true; } for (int nWUD = 0; nWUD < TableWUD.Rows.Count; nWUD++) { foreach (Invoice i in invList) { if (i.number == int.Parse(TableWUD.Rows[nWUD]["BillID"].ToString().Trim())) { nInvID = i.newID; break; } } // if (nInvID > 0) // { if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Date"].ToString().Trim())) { int nDate = int.Parse(TableWUD.Rows[nWUD]["Date"].ToString().Trim()); if (nDate <= 19820101 || nDate >= 21991231) { nDate = 20061231; } PCLaw.WUD.Date = nDate; } else { PCLaw.WUD.Date = 21991231; //assign arbitrary date } if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Explanation"].ToString().Trim())) { PCLaw.WUD.Explanation = TableWUD.Rows[nWUD]["Explanation"].ToString().Trim(); } else { PCLaw.WUD.Explanation = "Write Off - No Explanation Given"; } PCLaw.WUD.InvID = nInvID; PCLaw.WUD.MatterID = PLMatter.GetIDFromNN(TableWUD.Rows[nWUD]["MatterID"].ToString().Trim()); //only use this type per the PCLaw dev folks...FEE_WO_ADJ is broken PCLaw.WUD.Alloc.EntryType = PLWOAlloc.eWOAllocEntryType.FEE_WO_BADDEBT; PCLaw.WUD.TaskNN = "WD"; if (double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) > 0) { PCLaw.WUD.Alloc.Amount = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) * -1; } else { PCLaw.WUD.Alloc.Amount = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()); } PCLaw.WUD.Alloc.GLID = PLConvert.PLGLAccts.GetIDFromNN(TableWUD.Rows[nWUD]["GLAcct"].ToString().Trim()); PCLaw.WUD.Alloc.LawyerID = PLLawyer.GetIDFromNN(TableWUD.Rows[nWUD]["LawyerID"].ToString().Trim()); PCLaw.WUD.AddWOAllocation(); PCLaw.WUD.AddRecord(); PCLaw.WUD.SendLast(); /* } * else * {//write off is not associated with any invoice so we create a negative invoice (credit memo) * MessageBox.Show(TableWUD.Rows[nWUD]["BillID"].ToString().Trim() + " no invoicenum"); * if (!string.IsNullOrEmpty(TableWUD.Rows[nWUD]["Date"].ToString().Trim())) * { * int nDate = int.Parse(TableWUD.Rows[nWUD]["Date"].ToString().Trim()); * if (nDate <= 19820101 || nDate >= 21991231) * nDate = 20061231; * PCLaw.Bill.Date = nDate; * } * else * PCLaw.Bill.Date = 21991231; //assign arbitrary date * * //we need to see if amount is negative. If it is, keep the value, if not, make it negative * if (double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()) < 0) * PCLaw.Bill.Fees = double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()); * else * PCLaw.Bill.Fees = -double.Parse(TableWUD.Rows[nWUD]["Amount"].ToString().Trim()); * PCLaw.Bill.InvoiceNumber = iInvMum; * iInvMum--; * iInvMatterID = PLMatter.GetIDFromExtID1(TableWUD.Rows[nWUD]["MatterID"].ToString().Trim()); * PCLaw.Bill.MatterID = iInvMatterID; * PCLaw.Bill.CollLawyerID = PLMatter.GetRespFromMattID(iInvMatterID); * PCLaw.Bill.TypeOfLawID = PLMatter.GetTypeofLawFromMattID(iInvMatterID); * PCLaw.Bill.Alloc.Amount = PCLaw.Bill.Fees; * PCLaw.Bill.Alloc.LawyerID = PCLaw.Bill.CollLawyerID; * PCLaw.Bill.AddAllocation(); * PCLaw.Bill.AddRecord(ref iInvID, ref iInvNum, ref iInvDate); * * * PCLaw.TimeEntry.Date = iInvDate; * PCLaw.TimeEntry.InvDate = iInvDate; * PCLaw.TimeEntry.InvNumber = iInvNum; * PCLaw.TimeEntry.InvoiceID = iInvID; * PCLaw.TimeEntry.DateEntered = iInvDate; * PCLaw.TimeEntry.Amount = PCLaw.Bill.Fees; * PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY; * PCLaw.TimeEntry.Explanation = "Credit: " + TableWUD.Rows[nWUD]["Explanation"].ToString().Trim(); * PCLaw.TimeEntry.LawyerID = PLMatter.GetRespFromMattID(iInvMatterID); * PCLaw.TimeEntry.MatterID = iInvMatterID; * PCLaw.TimeEntry.TaskNN = "BW"; * PCLaw.TimeEntry.AddRecord(); * PCLaw.TimeEntry.SendLast(); * * } */ } }
} //end method private void addNotes() { int nNote = 0; int date = 0; int nValue = 0; DataTable Table = new DataTable("Note"); string sSelect = "SELECT * FROM [Note]"; ReadAMTable(ref Table, sSelect); for (nNote = 0; nNote < Table.Rows.Count; nNote++) { PCLaw.Diary.EntryType = PLConvert.PLDiary.eType.Notes; if (!string.IsNullOrEmpty(Table.Rows[nNote]["ShortDescription"].ToString().Trim())) { PCLaw.Diary.NoteShortDescription = Table.Rows[nNote]["ShortDescription"].ToString().Trim(); } else { PCLaw.Diary.NoteShortDescription = "General Note"; } if (!string.IsNullOrEmpty(Table.Rows[nNote]["Description"].ToString().Trim())) { PCLaw.Diary.Description = Table.Rows[nNote]["Description"].ToString().Trim(); } else { PCLaw.Diary.Description = "Converted Note - no memo text in original"; } PCLaw.Diary.MatterID = PLConvert.PLMatter.GetIDFromExtID1(Table.Rows[nNote]["MatterID"].ToString().Trim()); if (PCLaw.Diary.MatterID == 0) //matter is required. if no matter, do not add this note { PCLaw.Diary.Clear(); continue; }//end if date = int.Parse(Table.Rows[nNote]["EnteredDate"].ToString().Trim()); if (date < 19820101) { date = 19820101; } else { date = 20101231; } PCLaw.Diary.EnteredDate = date; date = int.Parse(Table.Rows[nNote]["DueDate"].ToString().Trim()); if (date < 19820101) { date = 19820101; } else { date = 20101231; }; PCLaw.Diary.DueDate = date; date = int.Parse(Table.Rows[nNote]["ReminderDate"].ToString().Trim()); if (date < 19820101) { date = 19820101; } else { date = 20101231; } PCLaw.Diary.ReminderDate = date; //add lawyers to diary entry string[] lawyers = Table.Rows[nNote]["LawyerIDs"].ToString().Split('|'); foreach (string lawyer in lawyers) { nValue = PLLawyer.GetIDFromExtID1(lawyer); if (nValue != 0) { PCLaw.Diary.AddLawyer(nValue); } }//end foreach //add contacts to diary entry string[] contacts = Table.Rows[nNote]["ContactIDs"].ToString().Split('|'); foreach (string contact in contacts) { if (int.Parse(Table.Rows[nNote]["ContactIDsAreClientIDs"].ToString()) == 1) { nValue = PLClient.GetContactIDFromClientID(int.Parse(contact)); } nValue = PLContact.GetIDFromExtID1(nValue.ToString()); if (nValue != 0) { PCLaw.Diary.AddContact(nValue); } }//end foreach //PCLaw.Diary.ExternalID_1 = Table.Rows[nContactCount]["OldID"].ToString().Trim(); PCLaw.Diary.AddRecord(); } //end for PCLaw.Diary.SendLast(); } //end method
//this step includes adding the invoices, allocations and time/expense entries for the invoices public void importBills(bool importClosedMatters) { DataTable TableBills = new DataTable("Bill"); DataTable TableAllocations = new DataTable("Allocation"); string sSelect = ""; string allocSelect = ""; int nInvID = 0; int nInvNum = 0; int nInvDate = 0; // bool usingAllocTable = true; // InvoiceToMatter itm = null; if (importClosedMatters) { PLBilling.m_bAllowEntOnClosedMtr = true; PLTimeEntry.m_bAllowEntOnClosedMtr = true; PLExpense.m_bAllowEntOnClosedMtr = true; } //glToID = getGLAcctIDs().ToList(); sSelect = "SELECT * from Bill"; ReadAMTable(ref TableBills, sSelect); allocSelect = "Select * from Allocation"; ReadAMTable(ref TableAllocations, allocSelect); //add bills and allocations for each bill (add all allocations to the bill before moving to the next bill) for (int nBill = 0; nBill < TableBills.Rows.Count; nBill++) { double allocFees = 0; double allocDisb = 0; //if (Convert.ToInt32(rdr["void_date"]) > 0) // continue; //voided invoice //handle interest only invoices? //skip invoice is there is no matter or invoice number if (!string.IsNullOrEmpty(TableBills.Rows[nBill]["MatterID"].ToString().Trim()) && !string.IsNullOrEmpty(TableBills.Rows[nBill]["BillNumber"].ToString().Trim())) { int nDate = int.Parse(TableBills.Rows[nBill]["Date"].ToString().Trim()); if (nDate <= 19820101 || nDate >= 21991231) { nDate = 20061231; } PCLaw.Bill.MatterID = PLMatter.GetIDFromNN(TableBills.Rows[nBill]["MatterID"].ToString().Trim()); PCLaw.Bill.CollLawyerID = PLLawyer.GetIDFromNN(TableBills.Rows[nBill]["LawyerID"].ToString().Trim()); if (PCLaw.Bill.CollLawyerID == 0) { PCLaw.Bill.CollLawyerID = PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID); } PCLaw.Bill.TypeOfLawID = PLMatter.GetTypeofLawFromMattID(PCLaw.Bill.MatterID); PCLaw.Bill.InvoiceNumber = Convert.ToInt32(TableBills.Rows[nBill]["BillNumber"].ToString().Trim()); PCLaw.Bill.Date = nDate; PCLaw.Bill.Fees = Math.Round(double.Parse(TableBills.Rows[nBill]["Fees"].ToString().Trim()), 2) + Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2); //what about interest? PCLaw.Bill.Disbs = Math.Round(double.Parse(TableBills.Rows[nBill]["Disb"].ToString().Trim()), 2); //to avoid problems with firms not using G/L accounting. Bug in PCLaw where Soft Costs are not 0 PCLaw.Bill.SoftCosts = 0; // if (!PCLaw.GenInf.UsingGST) // PCLaw.Bill.PSTFees = Math.Round(double.Parse(TableBills.Rows[nBill]["Taxes"].ToString().Trim()), 2); // else PCLaw.Bill.GSTFees = Math.Round(double.Parse(TableBills.Rows[nBill]["Taxes"].ToString().Trim()), 2); int nCollectID = PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID); //used to create generic entries in case the allocations do not match up with the invoice amounts //bill ready to go, now add allocations for (int nAllocs = 0; nAllocs < TableAllocations.Rows.Count; nAllocs++) { //only add allocations associated with this current bill, otherwise, ignore this allocation if (TableBills.Rows[nBill]["oldID"].ToString().Trim().Equals(TableAllocations.Rows[nAllocs]["BillID"].ToString().Trim(), StringComparison.OrdinalIgnoreCase)) { if (int.Parse(TableAllocations.Rows[nAllocs]["TimeExp"].ToString().Trim()) == 0) //time entry { //int nID = PLLawyer.GetIDFromNN(TableAllocations.Rows[nAllocs]["LawyerID"].ToString().Trim()); // if (nID.Equals(0)) // { // nID = PLLawyer.GetIDFromNN(TableAllocations.Rows[nAllocs]["LawyerID"].ToString().Trim()); // } // if (nID.Equals(0)) // PCLaw.Bill.Alloc.LawyerID = nCollectID; // else // PCLaw.Bill.Alloc.LawyerID = nID; PCLaw.Bill.Alloc.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID)); double dHours = Math.Round(Convert.ToDouble(TableAllocations.Rows[nAllocs]["QuantityHours"].ToString().Trim()), 2); PCLaw.Bill.Alloc.Amount = Math.Round(Convert.ToDouble(TableAllocations.Rows[nAllocs]["Total"].ToString().Trim()), 2); PCLaw.Bill.Alloc.Hours = dHours; //PCLaw.Bill.Alloc.Seconds = Convert.ToInt32(dHours * Convert.ToDouble(3600)); PCLaw.Bill.Alloc.GLNN = "4000." + PCLaw.Bill.Alloc.LawyerNN; //allocFees = allocFees + PCLaw.Bill.Alloc.Amount; PCLaw.Bill.AddAllocation(); } else //expense record { allocDisb = allocDisb + double.Parse(TableAllocations.Rows[nAllocs]["Total"].ToString().Trim()); } //Interest charges must match - TODO // if (!Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2).Equals(0.0)) // { // PCLaw.Bill.Alloc.Amount = Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2); // PCLaw.Bill.Alloc.Hours = 0.0; // PCLaw.Bill.Alloc.LawyerNN = // PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(PCLaw.Bill.MatterID)); // PCLaw.Bill.Alloc.GLNN = "4000." + PCLaw.Bill.Alloc.LawyerNN; // // PCLaw.Bill.AddAllocation(); // allocFees = allocFees + PCLaw.Bill.Alloc.Amount; // } } //end if } //end allocs for double feeDiff = 0.00; // feeDiff = Math.Round(double.Parse(TableBills.Rows[nBill]["Fees"].ToString().Trim()), 2) + Math.Round(double.Parse(TableBills.Rows[nBill]["Interest"].ToString().Trim()), 2) - allocFees; //handle mismatch of fees between invoice and sum if individual entries. //need a more graceful way to handle this //if (feeDiff != 0) // { //MessageBox.Show(TableBills.Rows[count]["oldID"].ToString().Trim() + " : " + feeDiff.ToString()); // PCLaw.Bill.Alloc.Amount = feeDiff; // PCLaw.Bill.Alloc.Hours = 0; // PCLaw.Bill.Alloc.LawyerID = nCollectID; //PCLaw.Bill.Alloc.GLNN = PCLaw.Bill.CollLawyerID; // PCLaw.Bill.AddAllocation(); // } //handle mismatch of disb between invoice and sum if individual entries. - currently there is only one disb per bill so it will always match // double disbDiff = Math.Round(double.Parse(TableBills.Rows[nBill]["Disb"].ToString().Trim()), 2) - allocDisb; // if (disbDiff != 0) // disbDiff = PCLaw.Bill.Disbs - allocDisb; //add the bill int matterID = PCLaw.Bill.MatterID; //saved for use later on time and expense entries Invoice i = new Invoice(); PCLaw.Bill.bAutoCreateCharges = false; PCLaw.Bill.ExternalID_1 = TableBills.Rows[nBill]["OldID"].ToString().Trim(); PCLaw.Bill.ExternalID_2 = TableBills.Rows[nBill]["BillNumber"].ToString().Trim(); PCLaw.Bill.AddRecord(ref nInvID, ref nInvNum, ref nInvDate); i.newID = nInvID; i.number = nInvNum; i.oldID = TableBills.Rows[nBill]["BillID"].ToString().Trim(); i.date = nInvDate; invList.Add(i); //allocs and bill done, now we add the time and expense entries associated with them //bill ready to go, now add allocations for (int allocs = 0; allocs < TableAllocations.Rows.Count; allocs++) { //only time/fee entries (allocations) associated with this current bill, otherwise, ignore this entry if (TableBills.Rows[nBill]["BillID"].ToString().Trim().Equals(TableAllocations.Rows[allocs]["BillID"].ToString().Trim(), StringComparison.OrdinalIgnoreCase)) { if (int.Parse(TableAllocations.Rows[allocs]["TimeExp"].ToString().Trim()) == 0) //time entry { PCLaw.TimeEntry.InvoiceID = nInvID; PCLaw.TimeEntry.InvNumber = nInvNum; PCLaw.TimeEntry.Date = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim()); PCLaw.TimeEntry.DateEntered = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim()); double dur = Convert.ToDouble(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim()); PCLaw.TimeEntry.Hours = dur; if (double.Parse(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim()) == 0.0000) { PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY; } else { PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.TimeEnt; } PCLaw.TimeEntry.MatterID = matterID; int taskID = 0; //if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim())) // taskID = PLTask.GetIDFromNN(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim()); // if (taskID == 0) // { taskID = PLTask.GetIDFromNN("BW"); // if (taskID == 0) // { // PCLaw.TimeEntry.TaskNN = "BW"; //// if (PCLaw.TimeEntry.TaskID.Equals(0)) // { // PCLaw.Task.Name = "Billable Work"; // PCLaw.Task.NickName = "BW"; // PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE; // PCLaw.Task.AddRecord(); // PCLaw.Task.SendLast(); // PCLaw.TimeEntry.TaskNN = "BW"; // } //} //} //else PCLaw.TimeEntry.TaskID = taskID; string descr = ""; if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["Description"].ToString().Trim())) { descr = TableAllocations.Rows[allocs]["Description"].ToString().Trim(); } if (descr.Equals("")) { descr = "Converted time entry, no explanaion provided"; } PCLaw.TimeEntry.Explanation = descr; int lawyerID = PLLawyer.GetIDFromNN(TableAllocations.Rows[allocs]["LawyerID"].ToString().Trim()); if (lawyerID.Equals(0)) { PCLaw.TimeEntry.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(matterID)); } else { PCLaw.TimeEntry.LawyerID = lawyerID; } if (double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim()) == 0.0) { try { if (Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()) != 0 && dur != 0) { PCLaw.TimeEntry.Rate = Math.Round(Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()) / dur, 2); } } catch (Exception ex1) { PCLaw.TimeEntry.Rate = double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim()); } } else { PCLaw.TimeEntry.Rate = double.Parse(TableAllocations.Rows[allocs]["Rate"].ToString().Trim()); } PCLaw.TimeEntry.Amount = Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()); PCLaw.TimeEntry.AddRecord(); } //end time entries else //expense entry { PCLaw.Expense.InvoiceID = nInvID; PCLaw.Expense.InvoiceNumber = nInvNum; PCLaw.Expense.Date = int.Parse(TableAllocations.Rows[allocs]["EntryDate"].ToString().Trim()); PCLaw.Expense.MatterID = matterID; string descr = ""; if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["Description"].ToString().Trim())) { descr = TableAllocations.Rows[allocs]["Description"].ToString().Trim(); } if (descr.Equals("")) { descr = "Converted expense, no explanaion provided"; } PCLaw.Expense.Explanation = descr; int explID = 0; if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim())) { explID = PLExpCode.GetIDFromNN(TableAllocations.Rows[allocs]["CodeID"].ToString().Trim()); } if (explID == 0) { PCLaw.Expense.ExplCodeID = PLExpCode.GetIDFromNN("A111"); //default code "other" } else { PCLaw.Expense.ExplCodeID = explID; } PCLaw.Expense.Quantity = Convert.ToDouble(TableAllocations.Rows[allocs]["QuantityHours"].ToString().Trim()); PCLaw.Expense.Rate = Convert.ToDouble(TableAllocations.Rows[allocs]["Rate"].ToString().Trim()); PCLaw.Expense.Amount = Convert.ToDouble(TableAllocations.Rows[allocs]["Total"].ToString().Trim()); PCLaw.Expense.IsSoftCost = false; if (string.IsNullOrEmpty(TableAllocations.Rows[allocs]["ExpensePaidTo"].ToString().Trim())) { PCLaw.Expense.PaidTo = "Converted - Billed Expenses"; } else { PCLaw.Expense.PaidTo = TableAllocations.Rows[allocs]["ExpensePaidTo"].ToString().Trim(); } if (!string.IsNullOrEmpty(TableAllocations.Rows[allocs]["GLAcctID"].ToString().Trim())) { int id = PLConvert.PLGLAccts.GetIDFromExtID2(TableAllocations.Rows[allocs]["GLAcctID"].ToString().Trim()); if (id == 0) { PCLaw.Expense.GLNN = "5210"; } else { PCLaw.Expense.GLNN = PLConvert.PLGLAccts.GetNNFromID(id); } } else { PCLaw.Expense.GLNN = "5210"; } PCLaw.Expense.AddRecord(); } //end expense entries (else) } //end outer if } //end time/expense for //if time and expense entries do not match bill, we add a generic entry to make them even /* * if (feeDiff != 0.00) * { * PCLaw.TimeEntry.Amount = feeDiff; * feeDiff = 0.0; * * PCLaw.TimeEntry.InvDate = nInvDate; * PCLaw.TimeEntry.InvoiceID = nInvID; * PCLaw.TimeEntry.InvNumber = nInvNum; * PCLaw.TimeEntry.Date = nInvDate; * PCLaw.TimeEntry.Seconds = 0; * PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY; * PCLaw.TimeEntry.MatterID = matterID; * PCLaw.TimeEntry.TaskNN = "BW"; * * if (PCLaw.TimeEntry.TaskID.Equals(0)) * { * PCLaw.Task.Name = "Billable Work"; * PCLaw.Task.NickName = "BW"; * PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE; * PCLaw.Task.AddRecord(); * PCLaw.Task.SendLast(); * PCLaw.TimeEntry.TaskNN = "BW"; * } * * PCLaw.TimeEntry.Explanation = "Time Offset - bill mismatch"; * PCLaw.TimeEntry.LawyerID = nCollectID; * * PCLaw.TimeEntry.AddRecord(); * } * * if (disbDiff != 0) * { * PCLaw.Expense.InvDate = nInvDate; * PCLaw.Expense.InvoiceID = nInvID; * PCLaw.Expense.InvoiceNumber = nInvNum; * PCLaw.Expense.Date = nInvDate; * PCLaw.Expense.MatterID = matterID; * PCLaw.Expense.IsSoftCost = false; * PCLaw.Expense.Explanation = "Conversion Repair"; * PCLaw.Expense.Amount = disbDiff; * disbDiff = 0.0; * PCLaw.Expense.PaidTo = "Expense Offset - Billed Expenses"; * PCLaw.Expense.GLNN = "5210"; * PCLaw.Expense.AddRecord(); * } * * * if (!Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2).Equals(0.0)) * { * PCLaw.TimeEntry.Amount = * Math.Round(double.Parse(TableBills.Rows[nBill]["interest"].ToString().Trim()), 2); * * PCLaw.TimeEntry.InvDate = nInvDate; * PCLaw.TimeEntry.InvoiceID = nInvID; * PCLaw.TimeEntry.InvNumber = nInvNum; * PCLaw.TimeEntry.Date = nInvDate; * PCLaw.TimeEntry.Seconds = 0; * PCLaw.TimeEntry.EntryType = PLTimeEntry.eFeeEntryType.FEE_ENTRY; * PCLaw.TimeEntry.MatterID = matterID; * PCLaw.TimeEntry.TaskNN = "BW"; * * if (PCLaw.TimeEntry.TaskID.Equals(0)) * { * PCLaw.Task.Name = "Billable Work"; * PCLaw.Task.NickName = "BW"; * PCLaw.Task.Category = PLTask.eCATEGORY.NON_BILLABLE; * PCLaw.Task.AddRecord(); * PCLaw.Task.SendLast(); * PCLaw.TimeEntry.TaskNN = "BW"; * } * * PCLaw.TimeEntry.Explanation = "Interest Charged on Invoice " + nInvNum.ToString(); * PCLaw.TimeEntry.LawyerNN = PLLawyer.GetNNFromID(PLMatter.GetRespFromMattID(matterID)); * * PCLaw.TimeEntry.AddRecord(); * } * */ } //end if } //end bills for PCLaw.TimeEntry.SendLast(); PCLaw.Expense.SendLast(); }
}//end method private void addCalendarEntries() { int nCalendar = 0; TimeSpan Duration; int nDate = 0; //int nDateEnd = 0; int nTimeStart = 0; int nValue = 0; DataTable Table = new DataTable("Appointment"); string sSelect = "SELECT * FROM [Appointment]"; ReadAMTable(ref Table, sSelect); for (nCalendar = 0; nCalendar < Table.Rows.Count; nCalendar++) { PCLaw.Diary.IsRecurringEntry = bool.Parse(Table.Rows[nCalendar]["IsRecurring"].ToString()); nDate = int.Parse(Table.Rows[nCalendar]["EnteredDate"].ToString().Trim()); if (nDate < 19820101) //if the date is before pclaw's min level, make it the min { nDate = 19820101; } PCLaw.Diary.EnteredDate = nDate; nDate = int.Parse(Table.Rows[nCalendar]["DueDate"].ToString().Trim()); if (nDate < 19820101) { nDate = 19820101; } PCLaw.Diary.DueDate = nDate; DateTime DateEnd; DateTime DateStart; if (double.Parse(Table.Rows[nCalendar]["Duration"].ToString()) == 0) { DateEnd = Convert.ToDateTime(Table.Rows[nCalendar]["DueDate"].ToString().Insert(6, "-").Insert(4, "-")); DateStart = Convert.ToDateTime(Table.Rows[nCalendar]["StartDate"].ToString().Insert(6, "-").Insert(4, "-")); Duration = DateEnd - DateStart; //duration of the event PCLaw.Diary.Duration = Duration.Days * 24 + Duration.Hours + Duration.Minutes / 60; } else { Duration = TimeSpan.FromHours(double.Parse(Table.Rows[nCalendar]["Duration"].ToString())); PCLaw.Diary.Duration = double.Parse(Duration.ToString()); } if (PCLaw.Diary.IsRecurringEntry)//if its recurring, we have work to do! { PCLaw.Diary.RecurringStartDate = int.Parse(Table.Rows[nCalendar]["RecurringStartDate"].ToString().Trim()); PCLaw.Diary.RecurringEndDate = int.Parse(Table.Rows[nCalendar]["RecurringEndDate"].ToString().Trim()); PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.CalendarDay; //1) Daily requires a number od days before repeating (rDaysDaily) //2) Monthly requires: // a) Which day of the month to repeat (rDayOfMonth) - OR- // b) Which week of the month (rWeekOfMonth) AND which day of the week to repeat (rDayOfWeek) //3) Quarterly requires a day of the month (rDayOfMonth) AND how many months before it repeats (rMonthsQuarterly) //4) Weekly requires a day of the week (rDayOfWeek) //5) Anually requires a month of the year (rMonthsOfYear) AND // a) Day of the month (rDayOfMonth) OR // b) Week of month (rWeekOfMonth) AND day of week (rDaysOfWeek) //Frequency means how often to make the appointment switch (int.Parse(Table.Rows[nCalendar]["RecurringType"].ToString())) { case 1: //Daily PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.CalendarDay; PCLaw.Diary.RecurringFreq = int.Parse(Table.Rows[nCalendar]["rDaysDaily"].ToString()); break; case 2: //Monthly PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Month; if (int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()) != 0) { PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()); } else { if (int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString()) != 0) { PCLaw.Diary.RecurringWeekOfMonth = int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString()); } if (PCLaw.Diary.RecurringWeekOfMonth == 0) { PCLaw.Diary.RecurringWeekOfMonth = 1; } switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString())) { case 1: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun; break; case 2: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; break; case 3: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue; break; case 4: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed; break; case 5: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur; break; case 6: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri; break; case 7: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat; break; default: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; break; } //end switch } //end else decimal month = Duration.Days / 30; // there are 30 days in an average month so days/30 = months PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(month)); //ceiling because we need an int here if (PCLaw.Diary.RecurringFreq < 1) { PCLaw.Diary.RecurringFreq = 1; } break; case 3: //Quarterly PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Month; PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()); PCLaw.Diary.RecurringFreq = int.Parse(Table.Rows[nCalendar]["rMonthsQuarterly"].ToString()); break; case 4: //Weekly PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Week; switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString())) { case 1: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun; break; case 2: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; //to do - change that type in plconvert break; case 3: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue; break; case 4: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed; break; case 5: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur; break; case 6: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri; break; case 7: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat; break; default: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; break; } //end switch decimal week = Duration.Days / 4; //there are 4 weeks in a month so days/4 = weeks PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(week)); if (PCLaw.Diary.RecurringFreq < 1) { PCLaw.Diary.RecurringFreq = 1; } break; case 5: //Annually PCLaw.Diary.RecurringRepeatUnit = PLDiary.eRepeatUnit.Year; PCLaw.Diary.RecurringMonthOfYear = int.Parse(Table.Rows[nCalendar]["rMonthsOfYear"].ToString()); if (int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()) != 0) { PCLaw.Diary.RecurringDayOfMonth = int.Parse(Table.Rows[nCalendar]["rDayOfMonth"].ToString()); } else { PCLaw.Diary.RecurringWeekOfMonth = int.Parse(Table.Rows[nCalendar]["rWeekOfMonth"].ToString()); switch (int.Parse(Table.Rows[nCalendar]["rDayOfWeek"].ToString())) { case 1: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sun; break; case 2: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; break; case 3: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Tue; break; case 4: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Wed; break; case 5: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Thur; break; case 6: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Fri; break; case 7: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Sat; break; default: PCLaw.Diary.RecurringDayOfWeek = PLConvert.PLDiary.eDay.Non; break; } //end switch } //end else decimal year = Duration.Days / 365; PCLaw.Diary.RecurringFreq = Convert.ToInt32(Math.Ceiling(year)); if (PCLaw.Diary.RecurringFreq < 1) { PCLaw.Diary.RecurringFreq = 1; } break; }//end switch with no default on purpose switch (int.Parse(Table.Rows[nCalendar]["HolidayRecurringBehavior"].ToString())) { case 1: PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.NextBusDay; break; case 2: PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.PrevBusDay; break; case 3: PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.SameDay; break; case 4: PCLaw.Diary.RecurringAdjust = PLDiary.eAdjust.CancelEntry; break; } //end switch } //end recurring if switch (int.Parse(Table.Rows[nCalendar]["EntryType"].ToString())) { case 0: PCLaw.Diary.EntryType = PLDiary.eType.Holiday; break; case 1: PCLaw.Diary.EntryType = PLDiary.eType.Appointment; break; case 2: PCLaw.Diary.EntryType = PLDiary.eType.TODO; break; }//end switch if (!string.IsNullOrEmpty(Table.Rows[nCalendar]["Description"].ToString())) { PCLaw.Diary.Description = Table.Rows[nCalendar]["Description"].ToString(); } else { PCLaw.Diary.Description = "Converted Event - No Description Available"; } if (PCLaw.Diary.EntryType == PLDiary.eType.Appointment) { //pclaw needs the time in this format hhmm as an int //nTimeStart = DateStart.Hour * 100 + DateStart.Minute; nTimeStart = int.Parse(Table.Rows[nCalendar]["StartTime"].ToString()); if (nTimeStart < 700 || nTimeStart > 2359) //why would this appointment happen before 7am or be greater than 11:59? { nTimeStart = 700; } PCLaw.Diary.StartTime = nTimeStart; //duration needs to be an double and is in hours which is why the funky math //PCLaw.Diary.Duration = Duration.Days * 24 + Duration.Hours + Duration.Minutes / 60; }//end if if (PCLaw.Diary.Duration <= 0) //duration cant be zero or negative { PCLaw.Diary.Duration = 0.5; } switch (int.Parse(Table.Rows[nCalendar]["Priority"].ToString())) { case 0: PCLaw.Diary.Priority = PLDiary.ePriority.Normal; break; case 1: PCLaw.Diary.Priority = PLDiary.ePriority.High; break; case 2: PCLaw.Diary.Priority = PLDiary.ePriority.Low; break; default: PCLaw.Diary.Priority = PLDiary.ePriority.Normal; break; }//end switch if (PCLaw.Diary.EntryType == PLDiary.eType.TODO) { if (!string.IsNullOrEmpty(Table.Rows[nCalendar]["Completed"].ToString())) { PCLaw.Diary.Completed = bool.Parse(Table.Rows[nCalendar]["Completed"].ToString()); } else { PCLaw.Diary.Completed = false; } if (PCLaw.Diary.Completed) { PCLaw.Diary.CompletionDate = int.Parse(Table.Rows[nCalendar]["CompletionDate"].ToString()); //always on time! (you can change this if required though) } }//end if PCLaw.Diary.DiaryCodeID = PLDiaryCode.GetIDFromExtID1(Table.Rows[nCalendar]["DiaryCodeID"].ToString()); PCLaw.Diary.MatterID = PLMatter.GetIDFromExtID1(Table.Rows[nCalendar]["MatterID"].ToString()); if (PCLaw.Diary.MatterID == 0) //not found and is required....diary entry not added { PCLaw.Diary.Clear(); continue; } //add lawyers to diary entry string[] lawyers = Table.Rows[nCalendar]["LawyerID"].ToString().Split('|'); foreach (string lawyer in lawyers) { nValue = PLLawyer.GetIDFromExtID1(lawyer); if (nValue != 0) { PCLaw.Diary.AddLawyer(nValue); } }//end foreach //add contacts to diary entry string[] contacts = Table.Rows[nCalendar]["ContactID"].ToString().Split('|'); foreach (string contact in contacts) { nValue = PLContact.GetIDFromExtID1(contact); if (nValue != 0) { PCLaw.Diary.AddContact(nValue); } }//end foreach nDate = int.Parse(Table.Rows[nCalendar]["ReminderDate"].ToString().Replace("-", "")); if (nDate < 19820101) { PCLaw.Diary.ReminderDate = PCLaw.Diary.DueDate; } else { PCLaw.Diary.ReminderDate = nDate; } PCLaw.Diary.MinutesToRemind = int.Parse(Table.Rows[nCalendar]["MinutesToRemind"].ToString()); PCLaw.Diary.AddRecord(); }//end for PCLaw.Diary.SendLast(); }//end method