diff --git a/db/changes/175_imported_to_invoicein_table.sql b/db/changes/175_imported_to_invoicein_table.sql new file mode 100644 index 00000000..3ba90d93 --- /dev/null +++ b/db/changes/175_imported_to_invoicein_table.sql @@ -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; diff --git a/inc/top.inc.php b/inc/top.inc.php index 88c75791..81e3e190 100755 --- a/inc/top.inc.php +++ b/inc/top.inc.php @@ -103,7 +103,11 @@ Ut Innbetaling (OCR/KID) Bank +dispatch ?>t=remittance.listincoming">Betaling/Remittering + */ +?> diff --git a/modules/department/model/department.class.php b/modules/department/model/department.class.php new file mode 100644 index 00000000..14f6dffe --- /dev/null +++ b/modules/department/model/department.class.php @@ -0,0 +1,23 @@ + $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 ""; + } + } +} +?> diff --git a/modules/fakturabank/model/fakturabank.class.php b/modules/fakturabank/model/fakturabank.class.php index 963620f8..9bf98010 100644 --- a/modules/fakturabank/model/fakturabank.class.php +++ b/modules/fakturabank/model/fakturabank.class.php @@ -1643,7 +1643,7 @@ public function registerincoming() { #Foreign currency if ($is_foreign) { - $datalineH['UnitCostPrice'] = exchange::convertToLocal($InvoiceO->DocumentCurrencyCode, $CustPrice); + $datalineH['UnitCustPrice'] = exchange::convertToLocal($InvoiceO->DocumentCurrencyCode, $CustPrice); $datalineH['ForeignCurrencyID'] = $InvoiceO->DocumentCurrencyCode; $datalineH['ForeignAmount'] = (float)$line->LineExtensionAmount + $line->TaxTotal->TaxAmount; $datalineH['ForeignConvRate'] = $conversion_rate; @@ -1655,8 +1655,6 @@ public function registerincoming() { $datalineH['TaxAmount'] = (float)$line->TaxTotal->TaxAmount; } - $datalineH['UnitCustPrice'] = $datalineH['UnitCostPrice']; - $datalineH['UnitCostPriceCurrencyID'] = exchange::getLocalCurrency(); $datalineH['UnitCustPriceCurrencyID'] = exchange::getLocalCurrency(); @@ -1665,6 +1663,14 @@ public function registerincoming() { $datalineH['TotalWithTax'] = $datalineH['TotalWithoutTax'] + $datalineH['TaxAmount']; + // If Quantity not zero, we can devide by it and get the tax amount per unit. If not then set the amount of + // one unit with tax to 100 + Vat percent of the amount of one unit without tax + if ($Quantity != 0) { + $datalineH['UnitCostPrice'] = $datalineH['UnitCustPrice'] + $datalineH['TaxAmount']/$Quantity; + } else { + $datalineH['UnitCostPrice'] = $datalineH['UnitCustPrice'] * (1 + $datalineH['Vat']/100.0); + } + $datalineH['InsertedByPersonID']= $_lib['sess']->get_person('PersonID'); $datalineH['InsertedDateTime'] = $_lib['sess']->get_session('Datetime'); $datalineH['UpdatedByPersonID'] = $_lib['sess']->get_person('PersonID'); diff --git a/modules/invoice/view/listoutgoing.php b/modules/invoice/view/listoutgoing.php index 719c41cb..37567204 100755 --- a/modules/invoice/view/listoutgoing.php +++ b/modules/invoice/view/listoutgoing.php @@ -138,7 +138,7 @@ submit(array('name' => 'action_auto_save','value' => "Lagre dato")) ?> is_valid_accountperiod($invoice_period, $_lib['sess']->get_person('AccessLevel')); - $valid_date = validDate($voucher_date); + $valid_date = $_lib['validation']->date($voucher_date); if ($valid_accountperiod && $valid_date) { list($nextJournalID, $nextMessage) = $accounting->get_next_available_journalid(array('type'=>'S', 'available' => true)); echo ' fakturanummer: ' . $nextJournalID; diff --git a/modules/invoice/view/record.inc b/modules/invoice/view/record.inc index 0175a4ab..ef4e1e97 100755 --- a/modules/invoice/view/record.inc +++ b/modules/invoice/view/record.inc @@ -1,11 +1,5 @@ format('Y-m-d') === $date; -} - $CustomerAccountPlanID = (int) $_POST["invoiceout_CustomerAccountPlanID_$InvoiceID"]; if ($CustomerAccountPlanID == 0 && $InvoiceID) { $CustomerAccountPlanID = $_lib['storage']->get_row(array('query' => 'SELECT CustomerAccountPlanID FROM invoiceout WHERE InvoiceID = ' . $InvoiceID))->CustomerAccountPlanID; @@ -31,7 +25,7 @@ if($_lib['input']->getProperty('action_invoice_update') or $_lib['input']->getPr } $invoice_date = $_POST['invoiceout_InvoiceDate_'.$InvoiceID]; - if (!validDate($invoice_date)) { + if (!$_lib['validation']->date($invoice_date)) { $_lib['message']->add('Ugyldig fakturadato '.$invoice_date.'!'); } else { $updated = false; @@ -78,7 +72,7 @@ elseif($_lib['input']->getProperty('action_auto_save')) { $message = ""; $voucher_periode = $_POST['voucher_period']; } - if (validDate($_POST['voucher_date'])) { + if ($_lib['validation']->date($_POST['voucher_date'])) { $voucher_date = $_POST['voucher_date']; } else { $voucher_date = "0000-00-00"; diff --git a/modules/invoicein/model/invoicein.class.php b/modules/invoicein/model/invoicein.class.php index eb9f62f7..cb2d9864 100644 --- a/modules/invoicein/model/invoicein.class.php +++ b/modules/invoicein/model/invoicein.class.php @@ -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; + } 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,12 +561,27 @@ 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 @@ -433,6 +589,8 @@ public function add() { 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
"; + print "Fakturaen er bilagsført
"; } } diff --git a/modules/invoicein/view/edit.php b/modules/invoicein/view/edit.php index 3388ee85..484d72de 100755 --- a/modules/invoicein/view/edit.php +++ b/modules/invoicein/view/edit.php @@ -9,6 +9,7 @@ includelogic('invoicein/invoicein'); $invoicein = new logic_invoicein_invoicein($_lib['input']->request); +$invoicein_status = new logic_invoicein_invoicein($_lib['input']->request); $tax_categories = array(); @@ -23,10 +24,17 @@ $accounting = new accounting(); require_once "record.inc"; +$tabindex = 1; + $get_invoice = "select I.* from $db_table as I where ID='$ID'"; #print "Get invoice " . $get_invoice . "
\n"; $invoicein = $_lib['storage']->get_row(array('query' => $get_invoice)); +// invoice with the specified id and fill its status +$invoicein_status->fill(array()); +$invoicein_status = $invoicein_status->current(); +if (!empty($invoicein_status->Status)) $_lib['message']->add($invoicein_status->Status); + $get_invoicefrom = "select * from accountplan where AccountPlanID=" . (int) $invoicein->SupplierAccountPlanID; #print "get_invoicefrom " . $get_invoicefrom . "
\n"; $invoicein->from = $_lib['storage']->get_row(array('query' => $get_invoicefrom)); @@ -59,10 +67,16 @@ get_session('LoginFormDate'); -$supplier_accountplan = $accounting->get_accountplan_object($invoicein->SupplierAccountPlanID); -$allowancecharge_query = "SELECT ac.AllowanceChargeID, ac.ChargeIndicator, a.AccountPlanID as InAccountPlanID, ac.Reason, ac.Amount, v.Percent as InVatPercent, case when a.VatID < 40 THEN a.VatID + 30 ELSE a.VatID END as InVatID - FROM allowancecharge ac LEFT JOIN accountplan a ON a.AccountPlanID = " . $supplier_accountplan->MotkontoResultat1 . " LEFT JOIN vat v ON v.VatID = a.VatID AND v.Active = 1 AND v.ValidFrom <= '" . $date . "' AND v.ValidTo >= '" . $date . "' +if (!is_null($invoicein->SupplierAccountPlanID) && $invoicein->SupplierAccountPlanID > 0) { + $supplier_accountplan = $accounting->get_accountplan_object($invoicein->SupplierAccountPlanID); + $allowancecharge_query = "SELECT ac.AllowanceChargeID, ac.ChargeIndicator, a.AccountPlanID as InAccountPlanID, ac.Reason, ac.Amount, v.Percent as InVatPercent, case when a.VatID < 40 THEN a.VatID + 30 ELSE a.VatID END as InVatID + FROM allowancecharge ac LEFT JOIN accountplan a ON a.AccountPlanID = " . (int)$supplier_accountplan->MotkontoResultat1 . " LEFT JOIN vat v ON v.VatID = a.VatID AND v.Active = 1 AND v.ValidFrom <= '" . $date . "' AND v.ValidTo >= '" . $date . "' WHERE ac.Active = 1"; +} else { + $allowancecharge_query = "SELECT ac.AllowanceChargeID, ac.ChargeIndicator, NULL as InAccountPlanID, ac.Reason, ac.Amount, NULL as InVatPercent, NULL as InVatID + FROM allowancecharge ac + WHERE ac.Active = 1"; +} $allowancecharge_result = $_lib['db']->db_query($allowancecharge_query); while($allowance_charge = $_lib['db']->db_fetch_assoc($allowancecharge_result)) { $allowances_charges[$allowance_charge["AllowanceChargeID"]] = $allowance_charge; @@ -191,9 +205,13 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { Bilagsnummer - VoucherType&voucher_JournalID=$invoicein->JournalID"; ?>&action_journalid_search=1" target="_new">VoucherType ?>JournalID ?> - Bilagsnummer - text(array('table'=>$db_table, 'field'=>'JournalID', 'pk' => $ID, 'value'=>$invoicein->JournalID, 'width'=>'30', 'tabindex' => $tabindex++)) ?> + + JournalID) { ?> + VoucherType&voucher_JournalID=$invoicein->JournalID"; ?>&action_journalid_search=1" target="_new">VoucherType ?>JournalID ?> + + + + Fakturanummer @@ -203,26 +221,26 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { Leverandør - accountplan_number_menu(array('table'=>$db_table, 'field'=>'SupplierAccountPlanID', 'pk'=>$ID, 'value'=>$invoicein->SupplierAccountPlanID, 'type' => array(0 => supplier))) ?> + accountplan_number_menu(array('table'=>$db_table, 'field'=>'SupplierAccountPlanID', 'pk'=>$ID, 'value'=>$invoicein->SupplierAccountPlanID, 'tabindex' => $tabindex++, 'type' => array(0 => supplier))) ?> Mottaker to->CompanyName ?> Betal til konto - text(array('table'=>$db_table, 'field'=>'SupplierBankAccount', 'pk' => $ID, 'value' => $invoicein->SupplierBankAccount)) ?> + text(array('table'=>$db_table, 'field'=>'SupplierBankAccount', 'pk' => $ID, 'value' => $invoicein->SupplierBankAccount, 'tabindex' => $tabindex++)) ?> Betal fra konto - select(array('table'=>$db_table, 'field'=>'CustomerBankAccount', 'pk' => $ID, 'value' => $invoicein->CustomerBankAccount, 'query' => 'form.BankAccount', 'width' => 30)) ?> + select(array('table'=>$db_table, 'field'=>'CustomerBankAccount', 'pk' => $ID, 'value' => $invoicein->CustomerBankAccount, 'query' => 'form.BankAccount', 'width' => 30, 'tabindex' => $tabindex++)) ?> Betal (beløp) - text(array('table'=>$db_table, 'field'=>'RemittanceAmount', 'pk'=>$ID, 'value' => $invoicein->RemittanceAmount)) ?> + Amount($invoicein->TotalCustPrice); ?> Betalingsmåte - select(array('table'=>$db_table, 'field'=>'PaymentMeans', 'pk' => $ID, 'value' => $invoicein->PaymentMeans, 'query' => 'form.PaymentMeans', 'width' => 30)) ?> + select(array('table'=>$db_table, 'field'=>'PaymentMeans', 'pk' => $ID, 'value' => $invoicein->PaymentMeans, 'query' => 'form.PaymentMeans', 'width' => 30, 'tabindex' => $tabindex++)) ?> - Org nr + Orgnr from->OrgNumber ?> - Org nr + Orgnr to->OrgNumber ?> @@ -272,8 +290,13 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { Forfalls dato text(array('table'=>$db_table, 'field'=>'DueDate', 'pk'=>$ID, 'value'=>substr($invoicein->DueDate,0,10), 'width'=>'30', 'tabindex'=> $tabindex++)) ?> +Imported) { ?> Er med i reisegarantifondet - Checkbox(array('table'=>$db_table, 'field'=>'isReisegarantifond', 'pk'=>$ID, 'value'=>$invoicein->isReisegarantifond)) ?> + Checkbox(array('table'=>$db_table, 'field'=>'isReisegarantifond', 'pk'=>$ID, 'value'=>$invoicein->isReisegarantifond, 'tabindex' => $tabindex++)) ?> + + + + Vår ref. @@ -288,15 +311,17 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { department_menu2(array('table' => $db_table, 'field' => 'DepartmentID', 'pk'=>$ID, 'value' => $invoicein->DepartmentID, 'unset' => true)); ?> - Leverings betingelse + Leveringsbetingelse text(array('table'=>$db_table, 'field'=>'DeliveryCondition', 'pk'=>$ID, 'value'=>$invoicein->DeliveryCondition, 'width'=>'30', 'tabindex'=>$tabindex++)) ?> - Betalings betingelse + Betalingsbetingelse text(array('table'=>$db_table, 'field'=>'PaymentCondition', 'pk'=>$ID, 'value'=>$invoicein->PaymentCondition, 'width'=>'30', 'tabindex'=>$tabindex++)) ?> Kommentar (intern) TextArea(array('table'=>$db_table, 'field'=>'CommentInternal', 'pk'=>$ID, 'value'=>$invoicein->CommentInternal, 'tabindex'=>$tabindex++, 'height'=>'5', 'width'=>'80')) ?> + Remitteringsstatus RemittanceStatus ?> @@ -322,12 +347,23 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { RemittanceDaySequence RemittanceDaySequence ?> +*/ +?> +Imported) { ?> + + Opprettet + InsertedDateTime ?> + Opprettet av + PersonIDToName($invoicein->InsertedByPersonID) ?> + + Hentet fra fakturabank FakturabankDateTime ?> Hentet fra fakturabank av PersonIDToName($invoicein->FakturabankPersonID) ?> + Konto ProduktNr - Produkt navn + Produktnavn Bil Antall Enhetspris + Enhetspris inkl. MVA MVA MVA beløp Beløp U/MVA @@ -424,6 +461,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { $aconf['width'] = '20'; $aconf['type'][] = 'result'; $aconf['type'][] = 'balance'; + $aconf['tabindex'] = $tabindex++; $accountplan = $accounting->get_accountplan_object($row2->AccountPlanID); print $_lib['form3']->accountplan_number_menu($aconf); ?> @@ -451,6 +489,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { ?> Input(array('type'=>'text', 'table'=>$db_table2, 'field'=>'QuantityDelivered', 'pk'=>$LineID, 'value'=>$row2->QuantityDelivered, 'width'=>'8', 'tabindex'=>$tabindex++, 'class'=>'number')) ?> Input(array('type'=>'text', 'table'=>$db_table2, 'field'=>'UnitCustPrice', 'pk'=>$LineID, 'value'=>$_lib['format']->Amount(array('value'=>$row2->UnitCustPrice, 'return'=>'value')), 'width'=>'15', 'tabindex'=>$tabindex++, 'class'=>'number')) ?> + Input(array('type'=>'text', 'table'=>$db_table2, 'field'=>'UnitCostPrice', 'pk'=>$LineID, 'value'=>$_lib['format']->Amount(array('value'=>$row2->UnitCostPrice, 'return'=>'value')), 'width'=>'15', 'tabindex'=>$tabindex++, 'class'=>'number')) ?> text(array('table'=>$db_table2, 'field'=>'Vat', 'pk'=>$LineID, 'value'=>$row2->Vat, 'width' => 5, 'maxlength' => 5, 'tabindex'=>$tabindex++)) ?> Amount($row2->TaxAmount) ?> Input(array('type'=>'text', 'table'=>$db_table2, 'field'=>'TotalWithoutTax', 'pk'=>$LineID, 'value'=>$_lib['format']->Amount(array('value'=>$row2->TotalWithoutTax, 'return'=>'value')), 'width'=>'15', 'tabindex'=>$tabindex++, 'class'=>'number')) ?> @@ -504,7 +543,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { ?> - AllowanceChargeType == 'line') print ''; ?> + AllowanceChargeType == 'line') print ''; ?> text(array( @@ -513,6 +552,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { 'pk' => $acrow->InvoiceLineAllowanceChargeID, 'value' => $_lib['format']->Amount(($acrow->ChargeIndicator == 1?1:-1)*$acrow->Amount), 'class' => 'number', + 'width' => '15', 'OnChange' => 'updateInvoiceLineAllowanceChargeData(this)', 'tabindex' => $tabindex++)); ?> @@ -527,7 +567,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { } } ?> -
+
$tabindex++)); ?> - + InvoiceAllowanceChargeID . '" >' . $_lib['format']->Percent($acrow->VatPercent) . ''; @@ -589,6 +629,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { 'pk' => $acrow->InvoiceAllowanceChargeID, 'value' => $_lib['format']->Amount(($acrow->ChargeIndicator == 1?1:-1)*$acrow->Amount), 'class' => 'number', + 'width' => '15', 'tabindex' => $tabindex++)); ?> @@ -600,7 +641,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { } } ?> -
+
@@ -628,7 +669,7 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { - + ExternalID) { ?>/invoices/ExternalID ?>" title="Vis i Fakturabank" target="_new">Vis i fakturabank get_person('AccessLevel') >= 2) { if($accounting->is_valid_accountperiod($_lib['date']->get_this_period($invoicein->Period), $_lib['sess']->get_person('AccessLevel'))) { - print $_lib['form3']->Input(array('type'=>'submit', 'name'=>'action_invoicein_update', 'value'=>'Lagre faktura (S)', 'accesskey'=>'S')); + print $_lib['form3']->Input(array('type'=>'submit', 'name'=>'action_invoicein_update', 'value'=>'Lagre faktura (S)', 'accesskey'=>'S', 'tabindex' => $tabindex++)); } else { print "Periode stengt"; } @@ -646,8 +687,19 @@ function updatePeriodFromInvoiceDate(invoice_date_element) { } } else { print "Faktura låst"; - } + } + ?> + + + + + is_valid_accountperiod($_lib['date']->get_this_period($invoicein->Period), $_lib['sess']->get_person('AccessLevel')) && ($_lib['sess']->get_person('AccessLevel') >= 4) && (!$invoicein->Imported) && (!$invoicein->JournalID)) { + print $_lib['form3']->Input(array('type'=>'submit', 'name'=>'action_invoicein_delete', 'value'=>'Slett faktura (D)', 'accesskey'=>'D', 'tabindex' => $tabindex++)); + } ?> + + Linje sum diff --git a/modules/invoicein/view/list.php b/modules/invoicein/view/list.php index aa5668ba..7974107d 100755 --- a/modules/invoicein/view/list.php +++ b/modules/invoicein/view/list.php @@ -17,6 +17,9 @@ require_once "record.inc"; +// get text for each of the payment means codes +$PaymentMeansCodes = $_lib['db']->get_hashhash(array('query' => "select MenuValue, MenuChoice from confmenues where MenuName='PaymentMeans' and LanguageID='no' order by MenuChoice", 'key' => 'MenuValue', 'value' => 'MenuChoice')); +foreach($PaymentMeansCodes as &$PaymentMeansCode) $PaymentMeansCode = $PaymentMeansCode['MenuChoice']; print $_lib['sess']->doctype; ?> @@ -77,11 +80,6 @@ Til: date(array('name' => 'ToDate', 'field' => 'ToDate', 'form_name' => 'invoice_edit1', 'value' => $invoicein->ToDate)) ?> - - Status: - text(array('name' => 'RemittanceStatus', 'value' => $invoicein->RemittanceStatus)) ?> - - Fakturanummer: text(array('name' => 'InvoiceNumber', 'value' => $invoicein->InvoiceNumber)) ?> @@ -121,11 +119,11 @@ Avdeling Årsaksinformasjon Bankkonto - Betaling + Betaling KID Fakturabank - Remittering Status + Opprettet som @@ -158,11 +156,11 @@ ?> TotalCustPrice != 0) {?> - Journaled) { ?>VoucherType&voucher_JournalID=$InvoiceO->JournalID"; ?>&action_journalid_search=1" target="_new">VoucherType ?>JournalID ?>VoucherType . $InvoiceO->JournalID; } ?> + Journaled) { ?>VoucherType&voucher_JournalID=$InvoiceO->JournalID"; ?>&action_journalid_search=1" target="_new">VoucherType ?>JournalID ?>Journal) { print $InvoiceO->VoucherType . $InvoiceO->JournalID; } ?> - InvoiceNumber ?> + InvoiceNumber) print $InvoiceO->InvoiceNumber; else print '-'; ?> InvoiceDate ?> Period ?> FirmaID ?> @@ -180,8 +178,15 @@ print $_lib['format']->Amount($InvoiceO->TotalCustPrice); ?> - ProjectID ?> - DepartmentID ?> + $InvoiceO->Department)); + + includelogic('project/project'); + $project = new lodo_project(array('ProjectID' => $InvoiceO->Project)); + ?> + Project != '') print $project->getProjectIDAndName(); ?> + Department != '') print $department->getDepartmentIDAndName(); ?> 40){ print substr($ReasonsInfo, 0, 37) . '...'; @@ -189,11 +194,11 @@ print $ReasonsInfo; } ?> SupplierBankAccount ?> - PaymentMeans ?> + PaymentMeans]; ?> KID ?> ExternalID) { ?>/invoices/ExternalID ?>" title="Vis i Fakturabank" target="_new">Vis i fakturabank - RemittanceStatus ?> Status ?> + Imported) ? 'importert' : 'manuelt'; ?> diff --git a/modules/invoicein/view/record.inc b/modules/invoicein/view/record.inc index d9dc237f..221127c6 100755 --- a/modules/invoicein/view/record.inc +++ b/modules/invoicein/view/record.inc @@ -1,6 +1,17 @@ getProperty('action_invoicein_linenew') || $_lib['input']->getProperty('action_invoicein_linedelete')) { + $ID = $_REQUEST['ID']; + $supplier_accountplan = $_lib['storage']->get_row(array('query' => "SELECT SupplierAccountPlanID FROM invoicein WHERE ID = " . $ID)); + $_REQUEST['invoicein_SupplierAccountPlanID_' . $ID] = $supplier_accountplan->SupplierAccountPlanID; +} + +if (isset($_POST['invoicein_InvoiceDate_'.$ID]) && !$_lib['validation']->date($_POST['invoicein_InvoiceDate_'.$ID])) { + $_lib['message']->add('Ugyldig fakturadato '.$_POST['invoicein_InvoiceDate_'.$ID].'!'); +} + if($_lib['input']->getProperty('action_invoicein_journal')) { - print "bilagsf¿r
"; $invoicein->journal(); } elseif($_lib['input']->getProperty('action_invoicein_update') or $_lib['input']->getProperty('action_invoiceline_new')) { @@ -22,13 +33,22 @@ if($_lib['input']->getProperty('action_invoicein_journal')) { } $invoicein->update($_POST); -} elseif($_lib['input']->getProperty('action_invoicein_remittance')) { +} elseif($_lib['input']->getProperty('action_invoicein_linenew')) { + $invoicein->linenew($_REQUEST); - includelogic('remittance/remittance'); +} elseif($_lib['input']->getProperty('action_invoicein_linedelete')) { + $invoicein->linedelete($_REQUEST); - $rem = new logic_remittance_remittance($_POST); - print $rem->fill(); - print $rem->pay(); +} elseif($_lib['input']->getProperty('action_invoicein_add')) { + $ID = $invoicein->add(); + header("Location: " . $_lib['sess']->dispatchs . "t=invoicein.edit&ID=" . $ID . "&inline=edit"); + die(); +} elseif($_lib['input']->getProperty('action_invoicein_delete')) { + $deleted = $invoicein->delete(); + if ($deleted) { + header("Location: " . $_lib['sess']->dispatchs . "t=invoicein.list"); + die(); + } } // Remove an allowance/charge from invoice line if($_lib['input']->getProperty('action_invoicein_line_allowance_charge_delete')) { diff --git a/modules/project/model/project.class.php b/modules/project/model/project.class.php new file mode 100644 index 00000000..3fffef6b --- /dev/null +++ b/modules/project/model/project.class.php @@ -0,0 +1,23 @@ + $value) { + $this->{$key} = $value; + } + } + + public function getProjectIDAndName() { + global $_lib; + if (isset($this->ProjectID)) { + $query_project = sprintf("SELECT * FROM project WHERE ProjectID = %d", $this->ProjectID); + $project_row = $_lib['storage']->get_row(array('query' => $query_project)); + $project_id_and_name = $project_row->ProjectID . " - " . $project_row->Heading; + return $project_id_and_name; + } else { + return ""; + } + } +} +?>