Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions db/changes/176_remove_fakturabank_email.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE fakturabankemail;
37 changes: 37 additions & 0 deletions db/changes/177_migrate_from_mail_to_phone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
-- Find NO:EMAIL FakturabankSchemeID;
SET @emailid = (SELECT FakturabankSchemeID FROM fakturabankscheme WHERE SchemeType = 'NO:EMAIL');

-- Create FirmaIDs for Employee Accountplans which have OrgNumber, but no appropriate FirmaID
-- In case we have a NO:EMAIL FirmaID with different value from ap.Email, this will create a new additional one;
INSERT INTO accountplanscheme (AccountPlanID, FakturabankSchemeID, SchemeValue, CountryCode)
SELECT ap.AccountPlanID, @emailid, ap.Email, 'NO'
FROM accountplan ap
LEFT JOIN accountplanscheme aps ON
ap.AccountPlanID = aps.AccountPlanID AND
ap.Email = aps.SchemeValue AND
aps.FakturabankSchemeID = @emailid
WHERE
ap.Email != '' AND ap.Email is not null AND
aps.AccountPlanSchemeID is null AND
ap.AccountPlanType = 'employee';


UPDATE fakturabankscheme SET SchemeType = REPLACE(SchemeType, ':TELEPHONE', ':PHONE');

-- Find NO:PHONE FakturabankSchemeID;
SET @phoneid = (SELECT FakturabankSchemeID FROM fakturabankscheme WHERE SchemeType = 'NO:PHONE');

-- Create FirmaIDs for Employee Accountplans which have OrgNumber, but no appropriate FirmaID
-- In case we have a NO:PHONE FirmaID with different value from ap.Phone, this will create a new additional one;
INSERT INTO accountplanscheme (AccountPlanID, FakturabankSchemeID, SchemeValue, CountryCode)
SELECT ap.AccountPlanID, @phoneid, ap.Phone, 'NO'
FROM accountplan ap
LEFT JOIN accountplanscheme aps ON
ap.AccountPlanID = aps.AccountPlanID AND
ap.Phone = aps.SchemeValue AND
aps.FakturabankSchemeID = @phoneid
WHERE
ap.Phone != '' AND ap.Phone is not null AND
aps.AccountPlanSchemeID is null AND
ap.AccountPlanType = 'employee';

166 changes: 73 additions & 93 deletions modules/accountplan/view/employee.php

Large diffs are not rendered by default.

67 changes: 31 additions & 36 deletions modules/accountplan/view/record.inc
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ function validate_employee($employee) {
$errors[] = "Personnr må stemme med fødselsdag.";
}

$fakturabankemail_query = "select * from fakturabankemail where AccountPlanID = " . $employee->AccountPlanID;
$fakturabankemail = $_lib['storage']->get_row(array('query' => $fakturabankemail_query));

if(!filter_var($fakturabankemail->Email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Ugyldig fakturabank epost.";
}

if(empty($employee->SocietyNumber) && empty($employee->IDNumber)) {
$errors[] = "Enten Personnr eller ID nummer på være der.";
} else {
Expand All @@ -52,33 +45,37 @@ function validate_employee($employee) {
}
}

if(empty($employee->Phone) && !filter_var($employee->Email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "Must have email or phone.";
}

return $errors;
}

function clean_org_number($orgnr) {
return preg_replace('/\s/', '', $orgnr);
}

function update_accountplan_field_from_scheme($field, $SchemeType) {
global $_lib;
$q = "UPDATE accountplan ap
LEFT JOIN accountplanscheme aps
ON ap.AccountPlanID = aps.AccountPlanID AND
aps.FakturabankSchemeID = (SELECT FakturabankSchemeID from fakturabankscheme WHERE SchemeType = '$SchemeType')
SET ap.$field = aps.SchemeValue
WHERE ap.AccountPlanID = '". $_POST["accountplan_AccountPlanID"] ."';";
$_lib['db']->db_query($q);
}

// updates OrgNumber and VatNumber from firmaids
function update_orgnr_vat_from_firmaid() {
global $_lib;
update_accountplan_field_from_scheme("OrgNumber", "NO:ORGNR");
update_accountplan_field_from_scheme("VatNumber", "NO:VAT");
}

$q_orgnr = "UPDATE accountplan ap
LEFT JOIN accountplanscheme aps
ON ap.AccountPlanID = aps.AccountPlanID AND
aps.FakturabankSchemeID = (SELECT FakturabankSchemeID from fakturabankscheme WHERE SchemeType = 'NO:ORGNR')
SET ap.OrgNumber = aps.SchemeValue
WHERE ap.AccountPlanID = '". $_POST["accountplan_AccountPlanID"] ."';";

$q_vat = "UPDATE accountplan ap
LEFT JOIN accountplanscheme aps
ON ap.AccountPlanID = aps.AccountPlanID AND
aps.FakturabankSchemeID = (SELECT FakturabankSchemeID from fakturabankscheme WHERE SchemeType = 'NO:VAT')
SET ap.VatNumber = aps.SchemeValue
WHERE ap.AccountPlanID = '". $_POST["accountplan_AccountPlanID"] ."';";

$_lib['db']->db_query($q_orgnr);
$_lib['db']->db_query($q_vat);
function update_phone_email_from_firmaid() {
update_accountplan_field_from_scheme("Phone", "NO:PHONE");
update_accountplan_field_from_scheme("Email", "NO:EMAIL");
}

// Removes all the firmaids whose accountplan is missing. This is useful in cases
Expand Down Expand Up @@ -149,16 +146,6 @@ if($_lib['input']->getProperty('action_accountplan_update') || $_lib['input']->g
$_lib['db']->db_query($password_sql);
}

if(isset($_POST['fakturabankemail_Email'])) {
$fakturabankemail_query = sprintf("DELETE FROM fakturabankemail WHERE AccountPlanID = %d", $AccountPlanID);
$_lib['db']->db_query($fakturabankemail_query);

$fakturabankemail_query = sprintf("INSERT INTO fakturabankemail (`AccountPlanID`, `Email`)
VALUES('%d', '%s');",
$AccountPlanID, mysql_escape_string($_POST['fakturabankemail_Email']));
$_lib['db']->db_query($fakturabankemail_query);
}

if(isset($_POST['accountplangln_GLN'])) {
$gln_query = sprintf("DELETE FROM accountplangln WHERE AccountPlanID = %d", $AccountPlanID);
$_lib['db']->db_query($gln_query);
Expand Down Expand Up @@ -397,7 +384,11 @@ elseif($_lib['input']->getProperty('action_del_scheme')) {
$query = sprintf("delete from accountplanscheme where AccountPlanSchemeID = %d", $id);
$_lib['db']->db_query($query);
}
update_orgnr_vat_from_firmaid();
if ($AccountPlanType == "employee") {
update_phone_email_from_firmaid();
} else {
update_orgnr_vat_from_firmaid();
}
}
elseif($_lib['input']->getProperty('action_save_scheme')) {
$no_sup_accnt_scheme = $_lib['db']->db_fetch_assoc($_lib['db']->db_query("SELECT FakturabankSchemeID FROM fakturabankscheme WHERE SchemeType = 'NO:SUP-ACCNT-RE';"));
Expand All @@ -412,7 +403,11 @@ elseif($_lib['input']->getProperty('action_save_scheme')) {
}
}
$_lib['storage']->db_update_multi_table($_POST, array('accountplanscheme' => 'AccountPlanSchemeID'));
update_orgnr_vat_from_firmaid();
if ($AccountPlanType == "employee") {
update_phone_email_from_firmaid();
} else {
update_orgnr_vat_from_firmaid();
}
if(!$accountexist) {
$fb = new lodo_fakturabank_fakturabank();
if (in_array($AccountPlanType, array('supplier', 'customer'))) $fb->update_accountplan_from_fakturabank($AccountPlanID);
Expand Down
17 changes: 0 additions & 17 deletions modules/accountplan/view/reskontro.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,10 @@
<meta name="cvs" content="$Id: reskontro.php,v 1.65 2005/11/03 15:33:11 thomasek Exp $" />
<? includeinc('head') ?>
<style type="text/css">
.highlighted {
background-color: #FFF655;
}
.read-only-input {
color: gray !important;
}
</style>
<script type="text/javascript">
function hightlightFirmaID() {
$("#firma_id_fields").addClass("highlighted");
setTimeout(function () {
$("#firma_id_fields").removeClass("highlighted");
}, 1000);
}
// this functions makes focus on the input next to the select which has selected value same as provided scheme_type
function focusFirmaidSchemeWithSchemetype(scheme_type) {
$("#firma_id_fields").find('select option:selected:contains("' + scheme_type + '")').parent("select").next("input").focus();
}
</script>
</head>
<body>

Expand Down Expand Up @@ -229,9 +214,7 @@ function focusFirmaidSchemeWithSchemetype(scheme_type) {
<td></td>
</tr>

<tbody id="firma_id_fields">
<? include("schemeid.php") ?>
</tbody>

<tr class="result">
<th colspan="6">Bilagsf&oslash;ringsinformasjon</th>
Expand Down
18 changes: 17 additions & 1 deletion modules/accountplan/view/schemeid.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<tbody id="firma_id_fields">
<?php
/* Integration against fakturabank scheme ids. Requires that $AccountPlanID is already defined */

Expand Down Expand Up @@ -51,7 +52,22 @@ function fixNoSupAccntRe(select_element) {
input.removeAttr("disabled");
}
}
function hightlightFirmaID() {
$("#firma_id_fields").addClass("highlighted");
setTimeout(function () {
$("#firma_id_fields").removeClass("highlighted");
}, 1000);
}
// this functions makes focus on the input next to the select which has selected value same as provided scheme_type
function focusFirmaidSchemeWithSchemetype(scheme_type) {
$("#firma_id_fields").find('select option:selected:contains("' + scheme_type + '")').parent("select").next("input").focus();
}
</script>
<style type="text/css">
.highlighted {
background-color: #FFF655;
}
</style>
<tr class="result">
<th colspan="6">Fakturabank Firma ID</th>
</tr>
Expand Down Expand Up @@ -92,5 +108,5 @@ function fixNoSupAccntRe(select_element) {
<? } ?>
</td>
</tr>

</tbody>

19 changes: 16 additions & 3 deletions modules/fakturabank/model/fakturabanksalary.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,18 @@ public function createSalaryXML($SalaryID, $SalaryConfID) {

global $_lib;

$query_head = "select S.*, F.Email AS FakturabankEmail, A.AccountName, A.Address, A.City, A.ZipCode, A.SocietyNumber, A.IDNumber, A.TabellTrekk, A.ProsentTrekk, A.Email, A.Address, A.ZipCode, A.LastName, A.FirstName, A.City, A.CountryCode, A.Phone, A.Mobile, S.DomesticBankAccount, P.Email as SavedByInLodo from salary as S, accountplan as A, fakturabankemail as F, person P where S.SalaryID='$SalaryID' and S.AccountPlanID=A.AccountPlanID and F.AccountPlanID = S.AccountPlanID and A.AccountPlanID = F.AccountPlanID and S.UpdatedBy = P.PersonID";
$query_head = "select S.*, A.AccountName, A.Address, A.City, A.ZipCode, A.SocietyNumber, A.IDNumber, A.TabellTrekk, A.ProsentTrekk, A.Email, A.Address, A.ZipCode, A.LastName, A.FirstName, A.City, A.CountryCode, A.Phone, A.Mobile, S.DomesticBankAccount, P.Email as SavedByInLodo from salary as S, accountplan as A, person P where S.SalaryID='$SalaryID' and S.AccountPlanID=A.AccountPlanID and S.UpdatedBy = P.PersonID";
#print "$query_head<br>";
$result_head = $_lib['db']->db_query($query_head);
$head = $_lib['db']->db_fetch_object($result_head);

$query_schemes = "select fbs.SchemeType as scheme, aps.SchemeValue as value from accountplanscheme aps join fakturabankscheme fbs on fbs.FakturabankSchemeID = aps.FakturabankSchemeID where AccountPlanID = '$head->AccountPlanID'";
$result_schemes = $_lib['db']->db_query($query_schemes);
$employee_schemes = array();
while($row = $_lib['db']->db_fetch_object($result_schemes)) {
$employee_schemes[] = $row;
}

$accountplan_edit_url = "/lodo.php?view_mvalines=&view_linedetails=&t=accountplan.employee&accountplan_AccountPlanID=" . $head->AccountPlanID;

if (empty($head)) {
Expand Down Expand Up @@ -217,8 +224,14 @@ public function createSalaryXML($SalaryID, $SalaryConfID) {
$xml_content .= "<employee_number>" . $head->AccountPlanID . "</employee_number>\n";
$xml_content .= "<first_name>" . $head->FirstName . "</first_name>\n";
$xml_content .= "<last_name>" . $head->LastName . "</last_name>\n";
$xml_content .= "<scheme>NO:EMAIL</scheme>\n";
$xml_content .= "<identifier>" . $head->FakturabankEmail . "</identifier>\n";

foreach ($employee_schemes as $scheme) {
$xml_content .= "<scheme>";
$xml_content .= "<identificator>" . $scheme->scheme . "</identificator>\n";
$xml_content .= "<identifier>" . $scheme->value . "</identifier>\n";
$xml_content .= "</scheme>";
}

$xml_content .= "<official_id_number>" . (empty($head->SocietyNumber) ? $head->IDNumber : $head->SocietyNumber) . "</official_id_number>\n";
$xml_content .= "<email>" . $head->Email . "</email>\n";

Expand Down
12 changes: 0 additions & 12 deletions modules/fakturabank/model/fakturabankvoting.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,12 +572,6 @@ public function find_account_plan_type($identity, $scheme_id, $type) {
return $r;
}
else if(preg_match("/:EMAIL$/", $scheme_id)) {
$query = "SELECT a.AccountPlanID FROM fakturabankemail e, accountplan a WHERE e.Email = '$identity' AND a.AccountPlanID = e.AccountPlanID AND a.AccountPlanType = '$type'";
$r = $_lib['storage']->get_row(array('query' => $query));
if($r)
return $r;

/* fall back to normal email */
$query = "SELECT AccountPlanID, OrgNumber FROM accountplan WHERE Email = '$identity' AND AccountPlanType = '$type'";
$r = $_lib['storage']->get_row(array('query' => $query));
if($r)
Expand Down Expand Up @@ -632,12 +626,6 @@ public function find_account_plan($identity, $scheme_id) {
return $_lib['storage']->get_row(array('query' => $query));
}
else if(preg_match("/:EMAIL$/", $scheme_id)) {
$query = "SELECT AccountPlanID FROM fakturabankemail WHERE Email = '$identity'";
$r = $_lib['storage']->get_row(array('query' => $query));
if($r)
return $r;

/* fall back to normal email */
$query = "SELECT AccountPlanID, OrgNumber FROM accountplan WHERE Email = '$identity'";
$r = $_lib['storage']->get_row(array('query' => $query));
if($r)
Expand Down
13 changes: 2 additions & 11 deletions modules/salary/view/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

$query_head = sprintf("
select
F.Email as FEmail,
S.*,
E.*,
A.ProsentTrekk as AP_ProsentTrekk,
Expand All @@ -43,11 +42,9 @@
salary as S
left join (salaryextra as E)
on (S.SalaryID = E.SalaryID),
fakturabankemail F,
accountplan A
where
S.SalaryID = '%d'
and F.AccountPlanID = S.AccountPlanID
and A.AccountPlanID = S.AccountPlanID
", $SalaryID);

Expand All @@ -57,7 +54,6 @@
if(!$head->isUpdated || isset($_POST['action_salary_update_extra'])) {
$query_head = "
select
F.Email as FEmail,
S.*,
A.AccountName,
A.Address,
Expand All @@ -69,12 +65,10 @@
A.ProsentTrekk as AP_ProsentTrekk
from
salary as S,
fakturabankemail F,
accountplan as A
where
S.SalaryID='$SalaryID'
and S.AccountPlanID=A.AccountPlanID
and F.AccountPlanID = A.AccountPlanID
";
$head = $_lib['storage']->get_row(array('query' => $query_head));
$query_arb = "select a.Percent from kommune as k, arbeidsgiveravgift as a where a.Code=k.Sone";
Expand Down Expand Up @@ -631,10 +625,7 @@
<td colspan="6">
<?
if($_lib['sess']->get_person('FakturabankExportPaycheckAccess')) {
if($head->FEmail)
print $_lib['form3']->Input(array('type'=>'submit', 'name'=>'action_salary_fakturabanksend', 'value'=>'Fakturabank (F)', 'accesskey'=>'F', 'disabled' => !$no_altinn_validation_errors));
else
print "Mangler fakturabankepost";
print $_lib['form3']->Input(array('type'=>'submit', 'name'=>'action_salary_fakturabanksend', 'value'=>'Fakturabank (F)', 'accesskey'=>'F', 'disabled' => !$no_altinn_validation_errors));
}

?>
Expand All @@ -648,7 +639,7 @@
if($_lib['sess']->get_person('AccessLevel') > 1 && $head->UpdatedBy) echo $head->UpdatedAt . " lagret av " . $_lib['format']->PersonIDToName($head->UpdatedBy);
?>
</td>
<td colspan = "4">Fakturabankepost: <?php print $head->FEmail; ?></td>
<td colspan = "4"></td>
</tr>
<tr>
<td colspan = "7">
Expand Down