-
Notifications
You must be signed in to change notification settings - Fork 0
Implement logic for creating a new incoming invoice #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mladjo2505
wants to merge
28
commits into
master
Choose a base branch
from
md/invoicein_new
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f4ddb65
Implement logic for creating a new incoming invoice
mladjo2505 baf4897
Fix tabindex on invoicein edit page
mladjo2505 628e3ea
Add unit price with tax to invoice lines in invoicein edit view
mladjo2505 4f08acb
Calculate total invoice amount on save for manually created invoices
mladjo2505 2ebe98c
Rename migration to next available number
mladjo2505 42ce21e
Add migration for clearing unit price with tax to 0
mladjo2505 af7fd7e
Fix invoicein import from fakturabank
mladjo2505 2386e62
Fix calculating invoice total amount
mladjo2505 e00d854
Do not show the JournalID for the invoices that cannot be bookkept
mladjo2505 e293baa
Show project and department names as well on invoicein list page
mladjo2505 7d5d7d5
Show who created the invoice and when if it was not imported
mladjo2505 7dbd255
Update invoicein fields correctly on date/supplier change
mladjo2505 33f5b87
Small fixes after codereview
mladjo2505 737d86b
Fix: Just print invoicein total amount, resolve missing accountplan
mladjo2505 35b1231
Fix after code review and discussion
mladjo2505 c98dca4
Small fixes after code review
mladjo2505 542c125
Fix typos on invoicein.edit page
mladjo2505 a93e7c0
Fix more stuff
mladjo2505 d4c2df6
Add invoice date validation to incoming invoice
mladjo2505 ce3f06b
Payment means should be printed as text
mladjo2505 a87998c
Fix for missing accountplan id for invoice in lines
mladjo2505 b8eed81
Recalculate invoice on save and delete
mladjo2505 49952c5
Add warning errors to invoice incoming
mladjo2505 070abd1
Remove more remittance stuff
mladjo2505 71bd82b
Additional fixes after code review
mladjo2505 ee52e7e
Fix invoicein show after rebase
mladjo2505 9bb74fe
Fix recalculate on save an some alignment on edit page
mladjo2505 4a3044d
Renumber migration
mladjo2505 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- Add imported to invoicein | ||
| ALTER TABLE invoicein | ||
| ADD Imported int(1) DEFAULT 1; | ||
|
|
||
| UPDATE invoiceinline SET UnitCostPrice = 0 WHERE Active = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <? | ||
|
|
||
| class lodo_department { | ||
|
|
||
| public function __construct($args) { | ||
| foreach($args as $key => $value) { | ||
| $this->{$key} = $value; | ||
| } | ||
| } | ||
|
|
||
| public function getDepartmentIDAndName() { | ||
| global $_lib; | ||
| if (isset($this->DepartmentID)) { | ||
| $query_department = sprintf("SELECT * FROM department WHERE DepartmentID = %d", $this->DepartmentID); | ||
| $department_row = $_lib['storage']->get_row(array('query' => $query_department)); | ||
| $department_id_and_name = $department_row->DepartmentID . " - " . $department_row->DepartmentName; | ||
| return $department_id_and_name; | ||
| } else { | ||
| return ""; | ||
| } | ||
| } | ||
| } | ||
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,9 @@ function fill($args) { | |
| if($this->ToDate) { | ||
| $query .= " i.InvoiceDate <= '$this->ToDate' and "; | ||
| } | ||
| if($this->ID) { | ||
| $query .= " i.ID = '$this->ID' and "; | ||
| } | ||
| if($this->PaymentMeans) { | ||
| $query .= " i.PaymentMeans = '$this->PaymentMeans' and "; | ||
| } | ||
|
|
@@ -120,7 +123,6 @@ function fill($args) { | |
| $row->Status .= "Er allerede bilagsført"; | ||
|
|
||
| } else { | ||
| $row->JournalID = $NextAvailableJournalID++; | ||
| $row->Journal = true; | ||
| $row->Class = 'green'; | ||
| } | ||
|
|
@@ -167,6 +169,12 @@ function fill($args) { | |
| $row->Class = 'red'; | ||
| } | ||
|
|
||
| if ($row->TotalCustPrice == 0) { | ||
| $row->Status .= "Faktura med beløp 0"; | ||
| $row->Journal = false; | ||
| } | ||
|
|
||
| if (!$row->Journaled && $row->Journal) $row->JournalID = $NextAvailableJournalID++; | ||
| $row->VoucherType = $this->VoucherType; | ||
| $this->iteratorH[] = $row; | ||
| } | ||
|
|
@@ -286,7 +294,12 @@ function update($args) { | |
|
|
||
| $ID = $args['ID']; | ||
| $AccountPlanID = $args['invoicein_SupplierAccountPlanID_' . $ID]; | ||
| $accountplan = $accounting->get_accountplan_object($AccountPlanID); | ||
| if (!is_numeric($AccountPlanID)) { | ||
| $_lib['message']->add('Leverandør ikke valgt!'); | ||
| $accountplan = NULL; | ||
| } else { | ||
| $accountplan = $accounting->get_accountplan_object($AccountPlanID); | ||
| } | ||
| $invoicein = $_lib['storage']->get_row(array('query' => "select * from invoicein where ID='$ID'")); | ||
|
|
||
| self::addVATPercentToAllowanceCharge($args); | ||
|
|
@@ -312,6 +325,53 @@ function update($args) { | |
| $_lib['message']->add('Sted mangler på leverandør kontoplan'); | ||
| } | ||
| } | ||
| if(!$invoicein->IName) { | ||
| if($accountplan->AccountName) { | ||
| $args['invoicein_IName_' . $ID] = $accountplan->AccountName; | ||
| $_lib['message']->add('Navn kopiert fra leverandør kontoplan'); | ||
| } else { | ||
| $_lib['message']->add('Navn mangler på leverandør kontoplan'); | ||
| } | ||
| } | ||
| if(!$invoicein->IAddress) { | ||
| if($accountplan->Address) { | ||
| $args['invoicein_IAddress_' . $ID] = $accountplan->Address; | ||
| $_lib['message']->add('Adresse kopiert fra leverandør kontoplan'); | ||
| } else { | ||
| $_lib['message']->add('Addresse mangler på leverandør kontoplan'); | ||
| } | ||
| } | ||
| $changed_supplier_accountplan = $invoicein->SupplierAccountPlanID != $AccountPlanID; | ||
|
|
||
| // update all supplier related info on the invoice | ||
| if($changed_supplier_accountplan) { | ||
| $args['invoicein_IZipCode_' . $ID] = $accountplan->ZipCode; | ||
| if(!$accountplan->ZipCode) $_lib['message']->add('Postnummer mangler på leverandør kontoplan'); | ||
| $args['invoicein_ICity_' . $ID] = $accountplan->City; | ||
| if(!$accountplan->City) $_lib['message']->add('Sted mangler på leverandør kontoplan'); | ||
| $args['invoicein_IName_' . $ID] = $accountplan->AccountName; | ||
| if(!$accountplan->AccountName) $_lib['message']->add('Navn mangler på leverandør kontoplan'); | ||
| $args['invoicein_IAddress_' . $ID] = $accountplan->Address; | ||
| if(!$accountplan->Address) $_lib['message']->add('Addresse mangler på leverandør kontoplan'); | ||
| $args['invoicein_SupplierBankAccount_' . $ID] = $accountplan->DomesticBankAccount; | ||
| if(!$accountplan->DomesticBankAccount) $_lib['message']->add('Kontonummer mangler på leverandør kontoplan'); | ||
| $args['invoicein_DZipCode_' . $ID] = $accountplan->ZipCode; | ||
| $args['invoicein_DName_' . $ID] = $accountplan->AccountName; | ||
| $args['invoicein_DCity_' . $ID] = $accountplan->City; | ||
| $args['invoicein_DAddress_' . $ID] = $accountplan->Address; | ||
| } | ||
| if(!$invoicein->DZipCode) { | ||
| $args['invoicein_DZipCode_' . $ID] = $accountplan->ZipCode; | ||
| } | ||
| if(!$invoicein->DName) { | ||
| $args['invoicein_DName_' . $ID] = $accountplan->AccountName; | ||
| } | ||
| if(!$invoicein->DCity) { | ||
| $args['invoicein_DCity_' . $ID] = $accountplan->City; | ||
| } | ||
| if(!$invoicein->DAddress) { | ||
| $args['invoicein_DAddress_' . $ID] = $accountplan->Address; | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All the delivery address fields should go to the upper if block, since they should be updated on account plan change. |
||
| if(!$invoicein->SupplierBankAccount) { | ||
| if($accountplan->DomesticBankAccount) { | ||
| $args['invoicein_SupplierBankAccount_' . $ID] = $accountplan->DomesticBankAccount; | ||
|
|
@@ -322,6 +382,31 @@ function update($args) { | |
| $_lib['message']->add('Kontonummer mangler på leverandør kontoplan'); | ||
| } | ||
| } | ||
| if(!$invoicein->CustomerAccountPlanID) { | ||
| $args['invoicein_CustomerAccountPlanID_' . $ID] = $_lib['sess']->get_companydef('OrgNumber'); | ||
| } | ||
| $args['invoicein_RemittanceAmount_'.$ID] = $args['invoicein_TotalCustPrice_'.$ID]; | ||
|
|
||
| // update UnitCustPrice(unit price without tax) from UnitCostPrice(unit price with tax) if it is set | ||
| for($i = 1; $i <= $args['field_count']; $i++) { | ||
| $line_id = $args[$i]; | ||
| if (!isset($args['invoiceinline_UnitCostPrice_'.$line_id])) continue; | ||
| $UnitCostPrice = (float)$_lib['convert']->Amount(array('value' => $args['invoiceinline_UnitCostPrice_'.$line_id], 'return' => 'value')); | ||
| $UnitCustPrice = (float)$_lib['convert']->Amount(array('value' => $args['invoiceinline_UnitCustPrice_'.$line_id], 'return' => 'value')); | ||
| $VATPercent = $_lib['convert']->Amount(array('value' => $args['invoiceinline_Vat_'.$line_id], 'return' => 'value'))/100.0; | ||
| if ($UnitCostPrice != 0) { | ||
| $args['invoiceinline_UnitCustPrice_'.$line_id] = $UnitCostPrice/($VATPercent+1); | ||
| // else update UnitCostPrice from UnitCustPrice | ||
| } elseif ($UnitCustPrice != 0) { | ||
| $args['invoiceinline_UnitCostPrice_'.$line_id] = $UnitCustPrice*($VATPercent+1); | ||
| } | ||
| } | ||
| // set the period as the period the invoice date belongs to | ||
| // and set due date if not set to X days after where X is credit days set for supplier | ||
| if ($args['invoicein_InvoiceDate_'.$ID] && !empty($args['invoicein_InvoiceDate_'.$ID])) { | ||
| $args['invoicein_Period_'.$ID] = strftime("%Y-%m", strtotime($args['invoicein_InvoiceDate_'.$ID])); | ||
| if ($args['invoicein_DueDate_'.$ID] == '0000-00-00' || $args['invoicein_DueDate_'.$ID] == '') $args['invoicein_DueDate_'.$ID] = strftime("%Y-%m-%d", strtotime($args['invoicein_InvoiceDate_'.$ID] . ' + ' . $accountplan->CreditDays . ' days')); | ||
| } | ||
|
|
||
| if(($args['invoicein_DepartmentID_'.$ID] === DB_NULL_PLACEHOLDER) && $accountplan->EnableDepartment == 1 && isset($accountplan->DepartmentID)) | ||
| $args['invoicein_DepartmentID_'.$ID] = $accountplan->DepartmentID; | ||
|
|
@@ -331,6 +416,11 @@ function update($args) { | |
|
|
||
| #print_r($accountplan); | ||
| #print_r($args); | ||
| for ($i = 1; $i <= $args['field_count']; $i++) { | ||
| $invoiceinline_id = $args[$i]; | ||
| $invoiceinline_accountplan = $accounting->get_accountplan_object($args['invoiceinline_AccountPlanID_'.$invoiceinline_id]); | ||
| if (!$invoiceinline_accountplan->EnableCar && !empty($args['invoiceinline_CarID_'.$invoiceinline_id])) $args['invoiceinline_CarID_'.$invoiceinline_id] = 0; | ||
| } | ||
|
|
||
| $tables_to_update = array( | ||
| 'invoicein' => 'ID', | ||
|
|
@@ -339,6 +429,45 @@ function update($args) { | |
| $this->line_allowance_charge_table => 'InvoiceLineAllowanceChargeID'); | ||
| $_lib['db']->db_update_multi_table($args, $tables_to_update); | ||
|
|
||
| // if manually created invoice(not imported from Fakturabank) | ||
| // calculate total cost for invoice | ||
| if (!$invoicein->Imported) { | ||
| $TotalCustPrice = self::recalculate_total_cust_price($ID); | ||
| $_lib['db']->db_update_multi_table(array('invoicein_TotalCustPrice_'.$ID => $TotalCustPrice), array('invoicein' => 'ID')); | ||
| } | ||
| } | ||
|
|
||
| // calculate total cost for invoice | ||
| function recalculate_total_cust_price($id) { | ||
| global $_lib; | ||
|
|
||
| $total = 0; | ||
|
|
||
| $query_invoicelines = "select * from invoiceinline where ID='$id' and Active <> 0 order by LineID asc"; | ||
| $result_invoicelines = $_lib['db']->db_query($query_invoicelines); | ||
| while($invoicein_line = $_lib['db']->db_fetch_object($result_invoicelines)) { | ||
| $unit_cust_price = $invoicein_line->UnitCustPrice; | ||
| $quantity_delivered = $invoicein_line->QuantityDelivered; | ||
| $line_cust_price = $unit_cust_price * $quantity_delivered; | ||
|
|
||
| // include line's allowance/charge | ||
| $query_invoicelines_allowance_charge = "select * from invoicelineallowancecharge where InvoiceLineID='$invoicein_line->LineID' and InvoiceType = 'in'"; | ||
| $result_invoicelines_allowance_charge = $_lib['db']->db_query($query_invoicelines_allowance_charge); | ||
| while($line_ac = $_lib['db']->db_fetch_object($result_invoicelines_allowance_charge)) { | ||
| $line_cust_price += (($line_ac->ChargeIndicator == 1) ? 1 : -1) * $line_ac->Amount; | ||
| } | ||
| $line_cost_price = $line_cust_price * (1 + ($invoicein_line->Vat / 100.0)); | ||
| $total += $line_cost_price; | ||
| } | ||
|
|
||
| // include ivoice's allowance/charge | ||
| $query_invoice_allowance_charge = "select * from invoiceallowancecharge where InvoiceID='$id' and InvoiceType = 'in'"; | ||
| $result_invoice_allowance_charge = $_lib['db']->db_query($query_invoice_allowance_charge); | ||
| while($ac = $_lib['db']->db_fetch_object($result_invoice_allowance_charge)) { | ||
| $ac_amount =(($ac->ChargeIndicator == 1) ? 1 : -1) * $ac->Amount * ( 1 + ($ac->VatPercent / 100.0)); | ||
| $total += $ac_amount; | ||
| } | ||
| return $total; | ||
| } | ||
|
|
||
| function linenew($args) { | ||
|
|
@@ -411,7 +540,19 @@ function linedelete($args) { | |
| $_lib['db']->db_delete($query); | ||
| $invoicelineH['Active'] = 0; | ||
| $invoicelineH['LineID'] = $args['LineID']; | ||
| return $_lib['storage']->store_record(array('table' => 'invoiceinline', 'data' => $invoicelineH, 'debug' => false)); | ||
|
|
||
| $ret = $_lib['storage']->store_record(array('table' => 'invoiceinline', 'data' => $invoicelineH, 'debug' => false)); | ||
|
|
||
| $ID = $args['ID']; | ||
| $invoicein = $_lib['storage']->get_row(array('query' => "select * from invoicein where ID='$ID'")); | ||
| // if manually created invoice(not imported from Fakturabank) | ||
| // calculate total cost for invoice | ||
| if (!$invoicein->Imported) { | ||
| $TotalCustPrice = self::recalculate_total_cust_price($ID); | ||
| $_lib['db']->db_update_multi_table(array('invoicein_TotalCustPrice_'.$ID => $TotalCustPrice), array('invoicein' => 'ID')); | ||
| } | ||
|
|
||
| return $ret; | ||
| } | ||
|
|
||
| /*************************************************************************** | ||
|
|
@@ -420,19 +561,36 @@ function linedelete($args) { | |
| * @return Current iteration | ||
| */ | ||
| public function add() { | ||
| global $_lib; | ||
| $dataH['CustomerBankAccount'] = $_lib['sess']->get_companydef('BankAccount'); | ||
| $old_pattern = array("/[^0-9]/"); | ||
| $new_pattern = array(""); | ||
| $dataH['CustomerAccountPlanID'] = strtolower(preg_replace($old_pattern, $new_pattern , $_lib['sess']->get_companydef('OrgNumber'))); | ||
| $add_invoicein = "INSERT INTO invoicein(ID, VoucherType, InvoiceDate, InsertedByPersonID, InsertedDateTime, Imported) VALUES(NULL, 'U', '" . $_lib['sess']->get_session('LoginFormDate') . "', " . $_lib['sess']->get_person('PersonID') . ", NOW(), 0)"; | ||
| $_lib['db']->db_insert($add_invoicein); | ||
| return $_lib['db']->db_insert_id(); | ||
| } | ||
|
|
||
| /*************************************************************************** | ||
| * Delete incoming invoice | ||
| */ | ||
| public function delete() { | ||
| global $_lib; | ||
| $delete_invoiceinlines = "DELETE FROM invoiceinline WHERE ID = " . $this->ID . " AND ID IN (SELECT DISTINCT(ID) FROM invoicein WHERE JournalID IS NULL)"; | ||
| $_lib['db']->db_delete($delete_invoiceinlines); | ||
| $delete_invoicein = "DELETE FROM invoicein WHERE ID = " . $this->ID . " AND JournalID IS NULL"; | ||
| $_lib['db']->db_delete($delete_invoicein); | ||
| return true; | ||
| } | ||
| ################################################################################################ | ||
| #Journal the invoices automatically. | ||
| #Set the invoices as registered in fakturabank | ||
| #update the bankaccount in accountplan. | ||
| public function journal() { | ||
| global $_lib, $accounting; | ||
|
|
||
| $countjournaled = 0; | ||
|
|
||
| if(is_array($this->iteratorH)) { | ||
| $this->Journaled = 1; //#So that we immideately list the journaled vouchers | ||
|
|
||
|
|
@@ -773,7 +931,7 @@ public function journal() { | |
| } | ||
| else { | ||
| # Invoice is bookkept | ||
| print "Fakturaen er bilagsf�rt<br>"; | ||
| print "Fakturaen er bilagsført<br>"; | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check out why this shows up on initial create for invoice