This commit is contained in:
2022-07-07 23:50:30 +00:00
parent 159835116c
commit 7d68f1126c
20 changed files with 1107 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ namespace AyaNovaQBI
public MainForm()
{
InitializeComponent();
this.Icon = AyaNovaQBI.Properties.Resources.logo;
Icon = AyaNovaQBI.Properties.Resources.logo;
}
async private void MainForm_Load(object sender, EventArgs e)
@@ -32,28 +32,37 @@ namespace AyaNovaQBI
await Task.Run(() => MessageBox.Show($"AyaNova QBI was unable to start:\r\n{initErrors.ToString()}"));
}
Close();
return;
}
else
{
//Confirm main settings and set any that are missing:
if (await util.ValidateSettings(false) == util.pfstat.Cancel)
{
await util.IntegrationLog("PFC: User settings not completed, user selected cancel");
Close();
}
//check if setup is required
//if (util.QBIntegration.Items.Count == 0)
//{
// MessageBox.Show("STUB: mainform,no maps, no integration data set");
//}
//Confirm main settings and set any that are missing:
if (await util.ValidateSettings(false) == util.pfstat.Cancel)
{
await util.IntegrationLog("PFC: User settings not completed, user selected cancel");
Close();
return;
}
Text = "AyaNova QBI - " + util.QCompanyName;
//See if there are *any* data mappings, if not then we will prompt the user to start that process
if (util.QBIntegration.Items.Count == 0)
{
//show message about mapping
MessageBox.Show(
"AyaNova QBI now needs you to map data between QuickBooks and AyaNova.",
"Setup mapping", MessageBoxButtons.OK, MessageBoxIcon.Information);
Map m = new Map();
if (m.ShowDialog() == DialogResult.Abort)
Close();
}
//Display billable workorders
InitInvoices();
grid.Visible = true;
menuStrip1.Enabled = true;
//MessageBox.Show("DONE / OK");
// grid.DataSource = util.GetInvoiceableItems();
}
private void grid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
@@ -116,18 +125,17 @@ namespace AyaNovaQBI
private async void preferencesToolStripMenuItem_Click(object sender, EventArgs e)
{
await util.ValidateSettings(true);
//TODO: CODE THIS InitInvoices();
}
private void mapAndImportToolStripMenuItem_Click(object sender, EventArgs e)
{
Map m = new Map();
if (m.ShowDialog() == DialogResult.Abort)
this.Close();
Close();
else
{
m.Dispose();
//todo: this.InitInvoices();
InitInvoices();
}
}
@@ -142,7 +150,7 @@ namespace AyaNovaQBI
MessageBox.Show(sVersion, "About");
}
private void onlineManualToolStripMenuItem_Click(object sender, EventArgs e)
{
util.OpenWebURL("https://ayanova.com/qbi/docs");
@@ -154,14 +162,224 @@ namespace AyaNovaQBI
await util.PopulateAyaListCache();
}
private async void invoiceDescriptiveTextTemplateToolStripMenuItem_Click(object sender, EventArgs e)
private async void invoiceDescriptiveTextTemplateToolStripMenuItem_Click(object sender, EventArgs e)
{
InvoiceTemplateBuilder b = new InvoiceTemplateBuilder();
b.ShowDialog();
if (util.QDat.IsDirty)
if (util.QDat.IsDirty)
await util.SaveIntegrationObject();
b.Dispose();
}
}
}
#region Main workorder grid
/// <summary>
/// Adjusts main form display to either show a list of billable workorders
/// or a status indicating there are none and why
/// </summary>
private void SetState()
{
fixProblemsToolStripMenuItem.Enabled = _MisMatches.Count > 0;
if (grid.Rows.Count > 0)
{
grid.Visible = true;
this.lblStatus.Visible = false;
}
else
{
StringBuilder sb = new StringBuilder();
sb.Append("No invoiceable work orders found in AyaNova\r\n\r\n");
sb.Append("A work order is invoiceable and will be listed here if it has:\r\n");
sb.Append(" - \"Invoice number\" field empty\r\n");
if (util.QDat.PreWOStatus != Guid.Empty)
{
sb.Append(" - \"Status\" field set to: ");
sb.Append(NameFetcher.GetItem("aWorkorderStatus", "aName", util.QDat.PreWOStatus));
sb.Append("\r\n");
sb.Append(" (You can change this status under Tools->Preferences in the menu)");
}
this.lblStatus.Text = sb.ToString();
grid.Visible = false;
this.lblStatus.Visible = true;
}
}
private WorkorderServiceBillableList _wolist = null;
private ArrayList _MisMatches = new ArrayList();
private ArrayList _PartPriceOverrides = new ArrayList();
/// <summary>
/// Initialize invoices dataset
/// from scratch. If a previous
/// initialize was done, wipe it and
/// repopulate from scratch
/// </summary>
private void InitInvoices()
{
Waiting w = new Waiting();
w.Show();
w.Ops = "Validating invoices...";
try
{
_MisMatches.Clear();
grid.BeginUpdate();
dsInvoices.Clear();
_wolist = WorkorderServiceBillableList.GetList(Util.QDat.PreWOStatus, true);
DataTable dtInvoice = dsInvoices.Tables["Invoices"];
DataTable dtWorkorder = dsInvoices.Tables["Workorders"];
foreach (WorkorderServiceBillableList.WorkorderServiceBillableListInfo i in _wolist)
{
bool bLinked = Util.ScanLinksOK(i.ID, _MisMatches, _PartPriceOverrides);
DataRow dri = InvoiceRowForClientID(i.ClientID);
w.Step = "WO: " + i.ServiceNumber;
if (dri == null)
{
dri = dtInvoice.NewRow();
dri["Client"] = i.Client;
dri["ClientID"] = i.ClientID;
dtInvoice.Rows.Add(dri);
}
//If any one single workorder is linked
//then the invoice is flagged as linked because
//you can invoice out anything under it that is linked and the
//not linked items simply won't invoice
if (bLinked)
dri["Linked"] = true;
DataRow drw = dtWorkorder.NewRow();
drw["InvoiceWorkingID"] = (int)dri["WorkingID"];
drw["WorkorderID"] = i.ID;
drw["Status"] = i.Status;
drw["ServiceNumber"] = i.ServiceNumber;
drw["ServiceDate"] = i.ServiceDate;
drw["Project"] = i.Project;
drw["StatusARGB"] = i.StatusARGB;
drw["Linked"] = bLinked;
dtWorkorder.Rows.Add(drw);
}
grid.DisplayLayout.Rows.CollapseAll(false);
foreach (UltraGridRow r in grid.Rows)
{
foreach (UltraGridRow rr in r.ChildBands[0].Rows)
{
if ((bool)rr.Cells["Linked"].Value == false)
r.Expanded = true;
}
}
grid.EndUpdate();
}
finally
{
w.Close();
}
SetState();
}
/// <summary>
/// Helper for grouping workorders by client
/// </summary>
/// <param name="ClientID"></param>
/// <returns>null if not found else datarow containing invoice for client</returns>
private DataRow InvoiceRowForClientID(Guid ClientID)
{
foreach (DataRow r in dsInvoices.Tables["Invoices"].Rows)
{
if ((Guid)r["ClientID"] == ClientID)
{
return r;
}
}
return null;
}
private void InitializeGrid()
{
grid.DataSource = dsInvoices;
string currentAssemblyDirectoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
//Load the grid layout from file
if (System.IO.File.Exists(currentAssemblyDirectoryName + "\\MainGrid.lyt"))
grid.DisplayLayout.Load(currentAssemblyDirectoryName + "\\MainGrid.lyt");
grid.DisplayLayout.Bands[0].Columns["WorkingID"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["ClientID"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["Linked"].Hidden = true;
grid.DisplayLayout.Bands[0].Columns["Client"].Header.Caption = "Invoice";
grid.DisplayLayout.Bands[1].Columns["InvoiceWorkingID"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["WorkorderID"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["StatusARGB"].Hidden = true;
grid.DisplayLayout.Bands[1].Columns["Linked"].Hidden = true;
}
private void grid_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
if (e.Row.Band.Index == 0)
{
//Prepare invoice row
if ((bool)e.Row.Cells["Linked"].Value == true)
{
e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("OK16");//Util.Image("OK16.png");
}
else
{
e.Row.Cells["Client"].Appearance.Image = Util.AyaImage("Cancel16");//Util.Image("Cancel16.png");
}
}
else
{
//prepare workorder row
//if backcolor==0 that means no color was set
int nColor = (int)e.Row.Cells["StatusARGB"].Value;
if (nColor != 0)
{
e.Row.Cells["Status"].Appearance.BackColor = Color.FromArgb(nColor);
e.Row.Cells["Status"].Appearance.ForeColor = Util.InvertColor(Color.FromArgb(nColor));
}
//flag whether billable (linked) or not
if ((bool)e.Row.Cells["Linked"].Value == true)
{
e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("OK16");
}
else
{
e.Row.Cells["ServiceNumber"].Appearance.Image = Util.AyaImage("Cancel16");
}
}
}
#endregion
}//eoc
}//eons