Completed
Push — master ( a18731...e2e070 )
by
unknown
99:54 queued 47:45
created

Opportunity::setWorkflowItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace OroCRM\Bundle\SalesBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
7
use Oro\Bundle\DataAuditBundle\Metadata\Annotation as Oro;
8
use Oro\Bundle\EmailBundle\Model\EmailHolderInterface;
9
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
10
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
11
use Oro\Bundle\OrganizationBundle\Entity\Organization;
12
use Oro\Bundle\UserBundle\Entity\User;
13
14
use OroCRM\Bundle\ChannelBundle\Model\ChannelEntityTrait;
15
use OroCRM\Bundle\ContactBundle\Entity\Contact;
16
use OroCRM\Bundle\SalesBundle\Model\ExtendOpportunity;
17
use OroCRM\Bundle\ChannelBundle\Model\ChannelAwareInterface;
18
19
/**
20
 * @ORM\Entity(repositoryClass="OroCRM\Bundle\SalesBundle\Entity\Repository\OpportunityRepository")
21
 * @ORM\Table(
22
 *      name="orocrm_sales_opportunity",
23
 *      indexes={@ORM\Index(name="opportunity_created_idx",columns={"created_at"})}
24
 * )
25
 * @ORM\HasLifecycleCallbacks()
26
 * @Oro\Loggable
27
 * @Config(
28
 *      routeName="orocrm_sales_opportunity_index",
29
 *      routeView="orocrm_sales_opportunity_view",
30
 *      defaultValues={
31
 *          "entity"={
32
 *              "icon"="icon-usd"
33
 *          },
34
 *          "ownership"={
35
 *              "owner_type"="USER",
36
 *              "owner_field_name"="owner",
37
 *              "owner_column_name"="user_owner_id",
38
 *              "organization_field_name"="organization",
39
 *              "organization_column_name"="organization_id"
40
 *          },
41
 *          "security"={
42
 *              "type"="ACL",
43
 *              "group_name"="",
44
 *              "category"="sales_data",
45
 *              "field_acl_supported" = "true"
46
 *          },
47
 *          "form"={
48
 *              "form_type"="orocrm_sales_opportunity_select",
49
 *              "grid_name"="sales-opportunity-grid",
50
 *          },
51
 *          "dataaudit"={
52
 *              "auditable"=true
53
 *          },
54
 *          "grid"={
55
 *              "default"="sales-opportunity-grid",
56
 *              "context"="sales-opportunity-for-context-grid"
57
 *          },
58
 *          "tag"={
59
 *              "enabled"=true
60
 *          }
61
 *     }
62
 * )
63
 *
64
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
65
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
66
 */
67
class Opportunity extends ExtendOpportunity implements
68
    EmailHolderInterface,
69
    ChannelAwareInterface
70
{
71
    use ChannelEntityTrait;
72
73
    const INTERNAL_STATUS_CODE = 'opportunity_status';
74
75
    /**
76
     * The key in system config for probability - status map
77
     */
78
    const PROBABILITIES_CONFIG_KEY = 'oro_crm_sales.default_opportunity_probabilities';
79
80
    /**
81
     * @var int
82
     *
83
     * @ORM\Id
84
     * @ORM\Column(type="integer", name="id")
85
     * @ORM\GeneratedValue(strategy="AUTO")
86
     * @ConfigField(
87
     *  defaultValues={
88
     *      "importexport"={
89
     *          "order"=0
90
     *      }
91
     *  }
92
     * )
93
     */
94
    protected $id;
95
96
    /**
97
     * @var OpportunityCloseReason
98
     *
99
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\OpportunityCloseReason")
100
     * @ORM\JoinColumn(name="close_reason_name", referencedColumnName="name")
101
     * @Oro\Versioned
102
     * @ConfigField(
103
     *  defaultValues={
104
     *      "dataaudit"={"auditable"=true},
105
     *      "importexport"={
106
     *          "order"=100,
107
     *          "short"=true
108
     *      }
109
     *  }
110
     * )
111
     **/
112
    protected $closeReason;
113
114
    /**
115
     * @var Contact
116
     *
117
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", cascade={"persist"})
118
     * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL")
119
     * @Oro\Versioned
120
     * @ConfigField(
121
     *  defaultValues={
122
     *      "dataaudit"={"auditable"=true},
123
     *      "importexport"={
124
     *          "order"=120,
125
     *          "short"=true
126
     *      },
127
     *      "form"={
128
     *          "form_type"="orocrm_contact_select"
129
     *      }
130
     *  }
131
     * )
132
     **/
133
    protected $contact;
134
135
    /**
136
     * @var Lead
137
     *
138
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Lead", inversedBy="opportunities")
139
     * @ORM\JoinColumn(name="lead_id", referencedColumnName="id", onDelete="SET NULL")
140
     * @Oro\Versioned
141
     * @ConfigField(
142
     *  defaultValues={
143
     *      "dataaudit"={"auditable"=true},
144
     *      "importexport"={
145
     *          "order"=130,
146
     *          "short"=true
147
     *      }
148
     *  }
149
     * )
150
     **/
151
    protected $lead;
152
153
    /**
154
     * @var User
155
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
156
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
157
     * @Oro\Versioned
158
     * @ConfigField(
159
     *  defaultValues={
160
     *      "dataaudit"={"auditable"=true},
161
     *      "importexport"={
162
     *          "order"=140,
163
     *          "short"=true
164
     *      }
165
     *  }
166
     * )
167
     */
168
    protected $owner;
169
170
    /**
171
     * @var string
172
     *
173
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
174
     * @Oro\Versioned
175
     * @ConfigField(
176
     *  defaultValues={
177
     *      "dataaudit"={"auditable"=true},
178
     *      "importexport"={
179
     *          "order"=10,
180
     *          "identity"=true
181
     *      }
182
     *  }
183
     * )
184
     */
185
    protected $name;
186
187
    /**
188
     * @var \DateTime
189
     *
190
     * @ORM\Column(name="close_date", type="date", nullable=true)
191
     * @Oro\Versioned
192
     * @ConfigField(
193
     *  defaultValues={
194
     *      "dataaudit"={"auditable"=true},
195
     *      "importexport"={
196
     *          "order"=20
197
     *      }
198
     *  }
199
     * )
200
     */
201
    protected $closeDate;
202
203
    /**
204
     * @var float
205
     *
206
     * @ORM\Column(name="probability", type="percent", nullable=true)
207
     * @Oro\Versioned
208
     * @ConfigField(
209
     *  defaultValues={
210
     *      "form"={
211
     *          "form_type"="oro_percent",
212
     *          "form_options"={
213
     *              "constraints"={{"Range":{"min":0, "max":100}}},
214
     *          }
215
     *      },
216
     *      "dataaudit"={
217
     *          "auditable"=true
218
     *      },
219
     *      "importexport"={
220
     *          "order"=30
221
     *      }
222
     *  }
223
     * )
224
     */
225
    protected $probability;
226
227
    /**
228
     * @var double
229
     *
230
     * @ORM\Column(name="budget_amount", type="money", nullable=true)
231
     * @Oro\Versioned
232
     * @ConfigField(
233
     *  defaultValues={
234
     *      "form"={
235
     *          "form_type"="oro_money",
236
     *          "form_options"={
237
     *              "constraints"={{"Range":{"min":0}}},
238
     *          }
239
     *      },
240
     *      "dataaudit"={
241
     *          "auditable"=true
242
     *      },
243
     *      "importexport"={
244
     *          "order"=40
245
     *      }
246
     *  }
247
     * )
248
     */
249
    protected $budgetAmount;
250
251
    /**
252
     * @var double
253
     *
254
     * @ORM\Column(name="close_revenue", type="money", nullable=true)
255
     * @Oro\Versioned
256
     * @ConfigField(
257
     *  defaultValues={
258
     *      "form"={
259
     *          "form_type"="oro_money",
260
     *          "form_options"={
261
     *              "constraints"={{"Range":{"min":0}}},
262
     *          }
263
     *      },
264
     *      "dataaudit"={
265
     *          "auditable"=true
266
     *      },
267
     *      "importexport"={
268
     *          "order"=50
269
     *      }
270
     *  }
271
     * )
272
     */
273
    protected $closeRevenue;
274
275
    /**
276
     * @var string
277
     *
278
     * @ORM\Column(name="customer_need", type="text", nullable=true)
279
     * @Oro\Versioned
280
     * @ConfigField(
281
     *  defaultValues={
282
     *      "dataaudit"={"auditable"=true},
283
     *      "importexport"={
284
     *          "order"=60
285
     *      }
286
     *  }
287
     * )
288
     */
289
    protected $customerNeed;
290
291
    /**
292
     * @var string
293
     *
294
     * @ORM\Column(name="proposed_solution", type="text", nullable=true)
295
     * @Oro\Versioned
296
     * @ConfigField(
297
     *  defaultValues={
298
     *      "dataaudit"={"auditable"=true},
299
     *      "importexport"={
300
     *          "order"=70
301
     *      }
302
     *  }
303
     * )
304
     */
305
    protected $proposedSolution;
306
307
    /**
308
     * @var \DateTime
309
     *
310
     * @ORM\Column(name="created_at", type="datetime")
311
     * @ConfigField(
312
     *      defaultValues={
313
     *          "entity"={
314
     *              "label"="oro.ui.created_at"
315
     *          },
316
     *          "importexport"={
317
     *              "excluded"=true
318
     *          }
319
     *      }
320
     * )
321
     */
322
    protected $createdAt;
323
324
    /**
325
     * @var \DateTime
326
     *
327
     * @ORM\Column(name="updated_at", type="datetime")
328
     * @ConfigField(
329
     *      defaultValues={
330
     *          "entity"={
331
     *              "label"="oro.ui.updated_at"
332
     *          },
333
     *          "importexport"={
334
     *              "excluded"=true
335
     *          }
336
     *      }
337
     * )
338
     */
339
    protected $updatedAt;
340
341
    /**
342
     * @var string
343
     *
344
     * @ORM\Column(name="notes", type="text", nullable=true)
345
     * @Oro\Versioned
346
     * @ConfigField(
347
     *      defaultValues={
348
     *          "dataaudit"={
349
     *              "auditable"=true
350
     *          },
351
     *          "importexport"={
352
     *              "order"=80
353
     *          }
354
     *      }
355
     * )
356
     */
357
    protected $notes;
358
359
    /**
360
     * @var Organization
361
     *
362
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\OrganizationBundle\Entity\Organization")
363
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
364
     */
365
    protected $organization;
366
367
    /**
368
     * @var B2bCustomer
369
     *
370
     * @ORM\ManyToOne(
371
     *     targetEntity="OroCRM\Bundle\SalesBundle\Entity\B2bCustomer",
372
     *     inversedBy="opportunities",
373
     *     cascade={"persist"}
374
     * )
375
     * @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="SET NULL")
376
     * @Oro\Versioned
377
     * @ConfigField(
378
     *  defaultValues={
379
     *      "dataaudit"={"auditable"=true},
380
     *      "importexport"={
381
     *          "order"=110,
382
     *          "short"=true
383
     *      },
384
     *      "form"={
385
     *          "form_type"="orocrm_sales_b2bcustomer_select"
386
     *      }
387
     *  }
388
     * )
389
     */
390
    protected $customer;
391
392
    /**
393
     * @return int
394
     */
395
    public function getId()
396
    {
397
        return $this->id;
398
    }
399
400
    /**
401
     * @param  Lead        $lead
402
     * @return Opportunity
403
     */
404
    public function setLead($lead)
405
    {
406
        $this->lead = $lead;
407
408
        return $this;
409
    }
410
411
    /**
412
     * @return Lead
413
     */
414
    public function getLead()
415
    {
416
        return $this->lead;
417
    }
418
419
    /**
420
     * @param  float       $budgetAmount
421
     * @return Opportunity
422
     */
423
    public function setBudgetAmount($budgetAmount)
424
    {
425
        $this->budgetAmount = $budgetAmount;
426
427
        return $this;
428
    }
429
430
    /**
431
     * @return float
432
     */
433
    public function getBudgetAmount()
434
    {
435
        return $this->budgetAmount;
436
    }
437
438
    /**
439
     * @param  \DateTime   $closeDate
440
     * @return Opportunity
441
     */
442
    public function setCloseDate($closeDate)
443
    {
444
        $this->closeDate = $closeDate;
445
446
        return $this;
447
    }
448
449
    /**
450
     * @return \DateTime
451
     */
452
    public function getCloseDate()
453
    {
454
        return $this->closeDate;
455
    }
456
457
    /**
458
     * @param  Contact     $contact
459
     * @return Opportunity
460
     */
461
    public function setContact($contact)
462
    {
463
        $this->contact = $contact;
464
465
        return $this;
466
    }
467
468
    /**
469
     * @return Contact
470
     */
471
    public function getContact()
472
    {
473
        return $this->contact;
474
    }
475
476
    /**
477
     * @param  string      $customerNeed
478
     * @return Opportunity
479
     */
480
    public function setCustomerNeed($customerNeed)
481
    {
482
        $this->customerNeed = $customerNeed;
483
484
        return $this;
485
    }
486
487
    /**
488
     * @return string
489
     */
490
    public function getCustomerNeed()
491
    {
492
        return $this->customerNeed;
493
    }
494
495
    /**
496
     * @param  float       $probability
497
     * @return Opportunity
498
     */
499
    public function setProbability($probability)
500
    {
501
        $this->probability = $probability;
502
503
        return $this;
504
    }
505
506
    /**
507
     * @return float
508
     */
509
    public function getProbability()
510
    {
511
        return $this->probability;
512
    }
513
514
    /**
515
     * @param  string      $proposedSolution
516
     * @return Opportunity
517
     */
518
    public function setProposedSolution($proposedSolution)
519
    {
520
        $this->proposedSolution = $proposedSolution;
521
522
        return $this;
523
    }
524
525
    /**
526
     * @return string
527
     */
528
    public function getProposedSolution()
529
    {
530
        return $this->proposedSolution;
531
    }
532
533
    /**
534
     * @param  string      $name
535
     * @return Opportunity
536
     */
537
    public function setName($name)
538
    {
539
        $this->name = $name;
540
541
        return $this;
542
    }
543
544
    /**
545
     * @return string
546
     */
547
    public function getName()
548
    {
549
        return $this->name;
550
    }
551
552
    /**
553
     * @param  OpportunityCloseReason $closeReason
554
     * @return Opportunity
555
     */
556
    public function setCloseReason($closeReason)
557
    {
558
        $this->closeReason = $closeReason;
559
560
        return $this;
561
    }
562
563
    /**
564
     * @return OpportunityCloseReason
565
     */
566
    public function getCloseReason()
567
    {
568
        return $this->closeReason;
569
    }
570
571
    /**
572
     * @param float $revenue
573
     */
574
    public function setCloseRevenue($revenue)
575
    {
576
        $this->closeRevenue = $revenue;
577
    }
578
579
    /**
580
     * @return float
581
     */
582
    public function getCloseRevenue()
583
    {
584
        return $this->closeRevenue;
585
    }
586
587
    /**
588
     * @return \DateTime
589
     */
590
    public function getCreatedAt()
591
    {
592
        return $this->createdAt;
593
    }
594
595
    /**
596
     * @param  \DateTime   $created
597
     * @return Opportunity
598
     */
599
    public function setCreatedAt($created)
600
    {
601
        $this->createdAt = $created;
602
603
        return $this;
604
    }
605
606
    /**
607
     * @return \DateTime
608
     */
609
    public function getUpdatedAt()
610
    {
611
        return $this->updatedAt;
612
    }
613
614
    /**
615
     * @param  \DateTime   $updated
616
     * @return Opportunity
617
     */
618
    public function setUpdatedAt($updated)
619
    {
620
        $this->updatedAt = $updated;
621
622
        return $this;
623
    }
624
625
    /**
626
     * Get the primary email address of the related contact
627
     *
628
     * @return string
629
     */
630
    public function getEmail()
631
    {
632
        $contact = $this->getContact();
633
        if (!$contact) {
634
            return null;
635
        }
636
637
        return $contact->getEmail();
638
    }
639
640
    public function __toString()
641
    {
642
        return (string) $this->getName();
643
    }
644
    /**
645
     * @ORM\PrePersist
646
     */
647
    public function beforeSave()
648
    {
649
        $this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
650
        $this->beforeUpdate();
651
    }
652
653
    /**
654
     * @ORM\PreUpdate
655
     */
656
    public function beforeUpdate()
657
    {
658
        $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
659
    }
660
661
    /**
662
     * @return User
663
     */
664
    public function getOwner()
665
    {
666
        return $this->owner;
667
    }
668
669
    /**
670
     * @param  User        $owningUser
671
     * @return Opportunity
672
     */
673
    public function setOwner($owningUser)
674
    {
675
        $this->owner = $owningUser;
676
677
        return $this;
678
    }
679
680
    /**
681
     * @return string
682
     */
683
    public function getNotes()
684
    {
685
        return $this->notes;
686
    }
687
688
    /**
689
     * @param  string      $notes
690
     * @return Opportunity
691
     */
692
    public function setNotes($notes)
693
    {
694
        $this->notes = $notes;
695
696
        return $this;
697
    }
698
699
    /**
700
     * @param B2bCustomer $customer
701
     * @TODO remove null after BAP-5248
702
     */
703
    public function setCustomer(B2bCustomer $customer = null)
704
    {
705
        $this->customer = $customer;
706
    }
707
708
    /**
709
     * @return B2bCustomer
710
     */
711
    public function getCustomer()
712
    {
713
        return $this->customer;
714
    }
715
716
    /**
717
     * Set organization
718
     *
719
     * @param Organization $organization
720
     * @return Opportunity
721
     */
722
    public function setOrganization(Organization $organization = null)
723
    {
724
        $this->organization = $organization;
725
726
        return $this;
727
    }
728
729
    /**
730
     * Get organization
731
     *
732
     * @return Organization
733
     */
734
    public function getOrganization()
735
    {
736
        return $this->organization;
737
    }
738
739
    /**
740
     * Remove Customer
741
     *
742
     * @return Lead
743
     */
744
    public function removeCustomer()
745
    {
746
        $this->customer = null;
747
    }
748
}
749