|
23 | 23 | switch (filter('op')) { |
24 | 24 | case 'crea_definitiva': |
25 | 25 | $year = date('Y', strtotime(post('date_start'))); |
| 26 | + $id_print = post('id_print'); |
| 27 | + $id_sezionale = post('id_sezionale'); |
| 28 | + $dir = post('dir'); |
| 29 | + $date_start = post('date_start'); |
| 30 | + $date_end = post('date_end'); |
26 | 31 |
|
27 | | - $first_page = $dbo->fetchOne('SELECT MAX(last_page) AS last_page FROM co_stampecontabili WHERE `id_print`='.prepare(post('id_print')).' AND `id_sezionale`='.prepare(post('id_sezionale')).' AND YEAR(`date_end`)='.prepare($year).' AND `dir`='.prepare(post('dir')))['last_page'] + 1; |
| 32 | + $where_conditions = [ |
| 33 | + '`id_print`='.prepare($id_print), |
| 34 | + 'YEAR(`date_end`)='.prepare($year) |
| 35 | + ]; |
28 | 36 |
|
29 | | - $print = Prints::render(post('id_print'), null, null, true, true, ['reset' => $first_page - 1, 'suppress' => 0]); |
| 37 | + if (!empty($id_sezionale)) { |
| 38 | + $where_conditions[] = '`id_sezionale`='.prepare($id_sezionale); |
| 39 | + } else { |
| 40 | + $where_conditions[] = '(`id_sezionale` IS NULL OR `id_sezionale` = "")'; |
| 41 | + } |
| 42 | + |
| 43 | + if (!empty($dir)) { |
| 44 | + $where_conditions[] = '`dir`='.prepare($dir); |
| 45 | + } else { |
| 46 | + $where_conditions[] = '(`dir` IS NULL OR `dir` = "")'; |
| 47 | + } |
| 48 | + |
| 49 | + $where_clause = implode(' AND ', $where_conditions); |
| 50 | + $first_page = $dbo->fetchOne('SELECT MAX(last_page) AS last_page FROM co_stampecontabili WHERE '.$where_clause)['last_page'] + 1; |
| 51 | + |
| 52 | + $print = Prints::render($id_print, null, null, true, true, ['reset' => $first_page - 1, 'suppress' => 0]); |
30 | 53 | $pages = count($print['pages']); |
31 | 54 | $last_page = $first_page + $pages - 1; |
32 | 55 |
|
33 | | - $result = $dbo->table('co_stampecontabili')->insertGetId([ |
34 | | - 'id_print' => post('id_print'), |
35 | | - 'id_sezionale' => post('id_sezionale') ?: '', |
36 | | - 'date_start' => post('date_start'), |
37 | | - 'date_end' => post('date_end'), |
| 56 | + $insert_data = [ |
| 57 | + 'id_print' => $id_print, |
| 58 | + 'date_start' => $date_start, |
| 59 | + 'date_end' => $date_end, |
38 | 60 | 'first_page' => $first_page, |
39 | 61 | 'last_page' => $last_page, |
40 | | - 'dir' => post('dir'), |
41 | | - ]); |
| 62 | + ]; |
| 63 | + |
| 64 | + if (!empty($id_sezionale)) { |
| 65 | + $insert_data['id_sezionale'] = $id_sezionale; |
| 66 | + } |
| 67 | + |
| 68 | + if (!empty($dir)) { |
| 69 | + $insert_data['dir'] = $dir; |
| 70 | + } |
| 71 | + |
| 72 | + $result = $dbo->table('co_stampecontabili')->insertGetId($insert_data); |
| 73 | + |
| 74 | + $print = Prints::render($id_print, null, null, true, true, ['reset' => $first_page - 1, 'suppress' => 0]); |
| 75 | + |
| 76 | + $print_name = $print['name']; |
| 77 | + $print_name = str_replace('.pdf', '', $print_name); |
| 78 | + $date_formatted = date('Y-m-d', strtotime($date_start)); |
| 79 | + |
| 80 | + if (!empty($dir)) { |
| 81 | + $dir_text = ($dir == 'entrata') ? 'vendite' : 'acquisti'; |
| 82 | + $name = $print_name.'_'.$dir_text.'_del_'.$date_formatted; |
| 83 | + } else { |
| 84 | + $name = $print_name.'_del_'.$date_formatted; |
| 85 | + } |
42 | 86 |
|
43 | | - $print = Prints::render(post('id_print'), null, null, true, true, ['reset' => $first_page - 1, 'suppress' => 0]); |
44 | | - $name = 'Registro_iva_'.(post('dir') == 'entrata' ? 'vendite' : 'acquisti').'_del_'.post('date_start'); |
45 | 87 | $upload = Uploads::upload($print['pdf'], [ |
46 | 88 | 'name' => $name, |
47 | 89 | 'original_name' => $name.'.pdf', |
|
0 commit comments