1 | <?php |
---|
2 | |
---|
3 | /** |
---|
4 | * PContactBeanBeforeSave |
---|
5 | * |
---|
6 | * @author Tomasz Świenty |
---|
7 | * @version 0.1 |
---|
8 | * @copyright Copyright (c) eDokumenty |
---|
9 | */ |
---|
10 | final class PContactBeanBeforeSave { |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | public static function init($args) { |
---|
15 | |
---|
16 | if (!isset($args['container'])) { |
---|
17 | return FALSE; |
---|
18 | } |
---|
19 | |
---|
20 | if (!is_object($args['container']) OR !is_a($args['container'], 'Bean')) { |
---|
21 | return FALSE; |
---|
22 | } |
---|
23 | |
---|
24 | $data = $args['container']->data; |
---|
25 | |
---|
26 | $contid = isset($data['contid']) ? $data['contid'] : FALSE; |
---|
27 | if (!$contid) { |
---|
28 | return FALSE; |
---|
29 | } |
---|
30 | |
---|
31 | require_once(MOD_PATH.'Contacts2/ContactsService.inc'); |
---|
32 | |
---|
33 | $contact = ContactsService::getRecord($contid); |
---|
34 | if (!$contact) { |
---|
35 | return FALSE; |
---|
36 | } |
---|
37 | |
---|
38 | $service = new ContactsService(); |
---|
39 | $address = $service->getMainAddress($contact); |
---|
40 | |
---|
41 | $nip___ = $contact->get('nip___'); |
---|
42 | $countr = $address ? $address->get('countr') : FALSE; |
---|
43 | |
---|
44 | if (!bs_empty_str($countr) AND in_array(mb_strtolower($countr), ['pl', 'polska']) AND bs_empty_str($nip___)) { |
---|
45 | throw new WidgetException('', Translator::translate('Klienci krajowi wymagają podania numeru NIP')); |
---|
46 | } |
---|
47 | |
---|
48 | } |
---|
49 | |
---|
50 | } |
---|
51 | |
---|
52 | if (isset($args)) { |
---|
53 | PContactBeanBeforeSave::init($args); |
---|
54 | } |
---|
55 | |
---|
56 | ?> |
---|