Skip to content

Commit

Permalink
Merge branch 'master' into sami/kerayksen_kuittaus_monirivi
Browse files Browse the repository at this point in the history
  • Loading branch information
Sami Luukkonen committed May 11, 2016
2 parents e2e05c7 + f0b1172 commit 711d786
Show file tree
Hide file tree
Showing 10 changed files with 518 additions and 447 deletions.
7 changes: 6 additions & 1 deletion UTF8_konversio.php
Expand Up @@ -34,6 +34,8 @@
$finfo1 = finfo_open(FILEINFO_MIME_TYPE);
$finfo2 = finfo_open(FILEINFO_MIME_ENCODING);

echo "Konvertoidaan Pupesoft UTF8 merkistöön";

foreach ($files as $file) {

if (strpos($file, "UTF8_konversio.php") !== FALSE) {
Expand All @@ -49,7 +51,8 @@

if (substr($mime, 0, 4) == "text" and $encd != "utf-8" and $encd != "us-ascii") {
$mitenmeni = system("recode ISO_8859-1..UTF8 $file");
echo "$file, $encd\n";
// echo "$file, $encd\n";
echo ".";
}

if ($vain_recode) {
Expand Down Expand Up @@ -164,3 +167,5 @@

finfo_close($finfo1);
finfo_close($finfo2);

echo "Valmis!\n";
169 changes: 166 additions & 3 deletions inc/functions.inc
Expand Up @@ -31498,7 +31498,7 @@ if (!function_exists("vapauta_maksusopimus")) {

if (!function_exists("tee_ennakkolasku")) {
function tee_ennakkolasku($jaks_alkup_tilaus, $sisainen = FALSE) {
global $yhtiorow, $kukarow, $palvelin2, $pupe_root_polku;
global $yhtiorow, $kukarow, $palvelin2, $pupe_root_polku, $force_web;

// Otetaan sopparin tiedot talteen jos sellanen on olemassa.
$jaksquery = "SELECT *
Expand Down Expand Up @@ -31555,7 +31555,7 @@ if (!function_exists("tee_ennakkolasku")) {

$ennakkokuvaus = mysql_fetch_assoc($kuvares);

mysql_data_seek($kuvares, mysql_num_rows($kuvares));
mysql_data_seek($kuvares, mysql_num_rows($kuvares) -1);
$loppukuvaus = mysql_fetch_assoc($kuvares);

if (!empty($soprow["maksuehto"])) {
Expand Down Expand Up @@ -31600,7 +31600,7 @@ if (!function_exists("tee_ennakkolasku")) {
$laskutettavat = $ennakkolasku;
$valittu_tulostin = "AUTOMAAGINEN_VALINTA";

require "verkkolasku.php";
require "{$pupe_root_polku}/tilauskasittely/verkkolasku.php";
}

// P�ivitet��n alkuper�iselle tilaukselle "jaksotettu" maksuehto
Expand Down Expand Up @@ -32761,3 +32761,166 @@ if (!function_exists('pupesoft_log')) {
fclose($file_handle);
}
}

if (!function_exists('tuoteperheen_lapsien_kertoimet')) {
function tuoteperheen_lapsien_kertoimet($isa_tuoteno, $tyyppi = 'P') {
global $yhtiorow, $kukarow;

$response = array();

$query = "SELECT
tuote.kehahin,
tuoteperhe.alekerroin,
tuoteperhe.hintakerroin,
tuoteperhe.hintatyyppi,
tuoteperhe.kerroin,
tuoteperhe.tuoteno
FROM tuoteperhe
JOIN tuote USING (yhtio, tuoteno)
WHERE tuoteperhe.yhtio = '{$kukarow['yhtio']}'
AND tuoteperhe.tyyppi = '{$tyyppi}'
AND tuoteperhe.isatuoteno = '{$isa_tuoteno}'
ORDER BY hintatyyppi DESC";
$result = pupe_query($query);

if (mysql_num_rows($result) == 0) {
return $response;
}

// haetaan eka rivi
$row = mysql_fetch_assoc($result);

// onko meill� is�tuotteeseen perustuva hinnoittelu
$hinnoittelu_isatuotteella = $row['hintatyyppi'];

// resultti alkuun
mysql_data_seek($result, 0);

$kokonaisarvo = 0;

// lasketaan koko tuoteperheen kokonaisarvo, t�t� tarvitaan arvokertoimen laskentaan
// arvokerrointa k�ytet��n, mik�li k�yt�ss� on is�tuotteen hintaan perustuva hinnoittelu
if (!empty($hinnoittelu_isatuotteella)) {
while ($row = mysql_fetch_assoc($result)) {
$kokonaisarvo += $row['kerroin'] * $row['kehahin'];
}

// resultti alkuun
mysql_data_seek($result, 0);
}

while ($row = mysql_fetch_assoc($result)) {
// jos hinnoitellaan is�tuotteella
// hintakerroin on lapsituotteen osuus kokonaisarvosta ja alekerroin ei ole k�yt�ss�
if (!empty($hinnoittelu_isatuotteella)) {
$alekerroin = 1;
$hintakerroin = $row['kehahin'] / $kokonaisarvo;
}
else {
$alekerroin = $row['alekerroin'];
$hintakerroin = $row['hintakerroin'];
}

$response[] = array(
"alekerroin" => (float) $alekerroin,
"hintakerroin" => (float) $hintakerroin,
"hintatyyppi" => $hinnoittelu_isatuotteella,
"kerroin" => (float) $row['kerroin'],
"tuoteno" => $row['tuoteno'],
);
}

return $response;
}
}

if (!function_exists('tuoteperheiden_hintojen_paivitys')) {
function tuoteperheiden_hintojen_paivitys($params) {
global $yhtiorow, $kukarow;

$isatunnukset = isset($params['isatunnukset']) ? $params['isatunnukset'] : array();
$tyyppi = isset($params['tyyppi']) ? $params['tyyppi'] : 'P';
$override = isset($params['override']) ? $params['override'] : false;

// tutkittavat rivitunnukset pit�� olla array
if (!is_array($isatunnukset) or count($isatunnukset) == 0) {
return;
}

foreach($isatunnukset as $isa => $perhe) {

$tunnukset = implode(", ", $perhe);

// Haetaan kaikki is�tuotteet
$query = "SELECT *
FROM tilausrivi
WHERE yhtio = '{$kukarow['yhtio']}'
AND tunnus = $isa
AND perheid = tunnus";
$result = pupe_query($query);
$row = mysql_fetch_assoc($result);

// katsotaan lapsien kertoimet
$kertoimet = tuoteperheen_lapsien_kertoimet($row['tuoteno'], $tyyppi);
$laskettu_hinta = 0;

$hinnoittelu_isatuotteella = ($kertoimet[0]['hintatyyppi'] == "I");

// Jos meill� ei ole is�tuotteeseen perustuva hinnoitelu, ei tarvitse tehd� mit��n,
// jos asetusta ei ole yliajettu parametreiss�
if ($hinnoittelu_isatuotteella === false && $override === false) {
continue;
}

foreach ($kertoimet as $lapsituote) {
// lasketaan lapsituotteen hinta is�n hinnasta
$hinta = round($row['hinta'] * $lapsituote['hintakerroin'], $yhtiorow['hintapyoristys']);
$laskettu_hinta += ($hinta * $row['tilkpl'] * $lapsituote['kerroin']);

// p�ivitet��n lapsituotteen hinta
$query = "UPDATE tilausrivi SET
ale1 = '{$row['ale1']}',
ale2 = '{$row['ale2']}',
ale3 = '{$row['ale3']}',
erikoisale = '{$row['erikoisale']}',
hinta = '{$hinta}',
netto = '{$row['netto']}'
WHERE yhtio = '{$kukarow['yhtio']}'
AND tuoteno = '{$lapsituote['tuoteno']}'
AND perheid = '{$row['perheid']}'
AND tilkpl = {$row['tilkpl']} * {$lapsituote['kerroin']}
AND tunnus != perheid
AND tunnus in ({$tunnukset})";
pupe_query($query);
}

// p�ivitet��n is�tuote nollaksi
$query = "UPDATE tilausrivi SET
ale1 = 0,
ale2 = 0,
ale3 = 0,
erikoisale = 0,
hinta = 0,
netto = ''
WHERE yhtio = '{$kukarow['yhtio']}'
AND tunnus = {$row['tunnus']}";
pupe_query($query);

// katsotaan py�ristysero
$pyoristysero = $laskettu_hinta - ($row['hinta'] * $row['tilkpl']);

// jos on py�ristyseroa
if ($pyoristysero != 0) {
$vikalapsi = array_pop($perhe);

// Lis�t��n py�ristys t�m�n perheen vikalle lapselle
$query = "UPDATE tilausrivi SET
hinta = round(hinta - ({$pyoristysero} / tilkpl), {$yhtiorow['hintapyoristys']})
WHERE yhtio = '{$kukarow['yhtio']}'
AND perheid = '{$row['perheid']}'
AND tunnus = $vikalapsi";
pupe_query($query);
}
}
}
}

0 comments on commit 711d786

Please sign in to comment.