Completed
Push — master ( bde6a0...48fd94 )
by
unknown
13:22
created

Opportunity::getClosedAt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
 *              "immutable"=true
54
 *          },
55
 *          "grid"={
56
 *              "default"="sales-opportunity-grid",
57
 *              "context"="sales-opportunity-for-context-grid"
58
 *          },
59
 *          "tag"={
60
 *              "enabled"=true
61
 *          }
62
 *     }
63
 * )
64
 *
65
 * @SuppressWarnings(PHPMD.ExcessivePublicCount)
66
 * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
67
 */
68
class Opportunity extends ExtendOpportunity implements
69
    EmailHolderInterface,
70
    ChannelAwareInterface
71
{
72
    use ChannelEntityTrait;
73
74
    const INTERNAL_STATUS_CODE = 'opportunity_status';
75
76
    const STATUS_LOST = 'lost';
77
    const STATUS_WON  = 'won';
78
79
    /**
80
     * The key in system config for probability - status map
81
     */
82
    const PROBABILITIES_CONFIG_KEY = 'oro_crm_sales.default_opportunity_probabilities';
83
84
    /**
85
     * @var int
86
     *
87
     * @ORM\Id
88
     * @ORM\Column(type="integer", name="id")
89
     * @ORM\GeneratedValue(strategy="AUTO")
90
     * @ConfigField(
91
     *  defaultValues={
92
     *      "importexport"={
93
     *          "order"=0
94
     *      }
95
     *  }
96
     * )
97
     */
98
    protected $id;
99
100
    /**
101
     * @var OpportunityCloseReason
102
     *
103
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\OpportunityCloseReason")
104
     * @ORM\JoinColumn(name="close_reason_name", referencedColumnName="name")
105
     * @Oro\Versioned
106
     * @ConfigField(
107
     *  defaultValues={
108
     *      "dataaudit"={"auditable"=true},
109
     *      "importexport"={
110
     *          "order"=100,
111
     *          "short"=true
112
     *      }
113
     *  }
114
     * )
115
     **/
116
    protected $closeReason;
117
118
    /**
119
     * @var Contact
120
     *
121
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\ContactBundle\Entity\Contact", cascade={"persist"})
122
     * @ORM\JoinColumn(name="contact_id", referencedColumnName="id", onDelete="SET NULL")
123
     * @Oro\Versioned
124
     * @ConfigField(
125
     *  defaultValues={
126
     *      "dataaudit"={"auditable"=true},
127
     *      "importexport"={
128
     *          "order"=120,
129
     *          "short"=true
130
     *      },
131
     *      "form"={
132
     *          "form_type"="orocrm_contact_select"
133
     *      }
134
     *  }
135
     * )
136
     **/
137
    protected $contact;
138
139
    /**
140
     * @var Lead
141
     *
142
     * @ORM\ManyToOne(targetEntity="OroCRM\Bundle\SalesBundle\Entity\Lead", inversedBy="opportunities")
143
     * @ORM\JoinColumn(name="lead_id", referencedColumnName="id", onDelete="SET NULL")
144
     * @Oro\Versioned
145
     * @ConfigField(
146
     *  defaultValues={
147
     *      "dataaudit"={"auditable"=true},
148
     *      "importexport"={
149
     *          "order"=130,
150
     *          "short"=true
151
     *      }
152
     *  }
153
     * )
154
     **/
155
    protected $lead;
156
157
    /**
158
     * @var User
159
     * @ORM\ManyToOne(targetEntity="Oro\Bundle\UserBundle\Entity\User")
160
     * @ORM\JoinColumn(name="user_owner_id", referencedColumnName="id", onDelete="SET NULL")
161
     * @Oro\Versioned
162
     * @ConfigField(
163
     *  defaultValues={
164
     *      "dataaudit"={"auditable"=true, "immutable"=true},
165
     *      "importexport"={
166
     *          "order"=140,
167
     *          "short"=true
168
     *      }
169
     *  }
170
     * )
171
     */
172
    protected $owner;
173
174
    /**
175
     * @var string
176
     *
177
     * @ORM\Column(name="name", type="string", length=255, nullable=false)
178
     * @Oro\Versioned
179
     * @ConfigField(
180
     *  defaultValues={
181
     *      "dataaudit"={"auditable"=true},
182
     *      "importexport"={
183
     *          "order"=10,
184
     *          "identity"=true
185
     *      }
186
     *  }
187
     * )
188
     */
189
    protected $name;
190
191
    /**
192
     * @var \DateTime
193
     *
194
     * @ORM\Column(name="close_date", type="date", nullable=true)
195
     * @Oro\Versioned
196
     * @ConfigField(
197
     *  defaultValues={
198
     *      "dataaudit"={"auditable"=true, "immutable"=true},
199
     *      "importexport"={
200
     *          "order"=20
201
     *      }
202
     *  }
203
     * )
204
     */
205
    protected $closeDate;
206
207
    /**
208
     * @var float
209
     *
210
     * @ORM\Column(name="probability", type="percent", nullable=true)
211
     * @Oro\Versioned
212
     * @ConfigField(
213
     *  defaultValues={
214
     *      "form"={
215
     *          "form_type"="oro_percent",
216
     *          "form_options"={
217
     *              "constraints"={{"Range":{"min":0, "max":100}}},
218
     *          }
219
     *      },
220
     *      "dataaudit"={"auditable"=true, "immutable"=true},
221
     *      "importexport"={
222
     *          "order"=30
223
     *      }
224
     *  }
225
     * )
226
     */
227
    protected $probability;
228
229
    /**
230
     * @var double
231
     *
232
     * @ORM\Column(name="budget_amount", type="money", nullable=true)
233
     * @Oro\Versioned
234
     * @ConfigField(
235
     *  defaultValues={
236
     *      "form"={
237
     *          "form_type"="oro_money",
238
     *          "form_options"={
239
     *              "constraints"={{"Range":{"min":0}}},
240
     *          }
241
     *      },
242
     *      "dataaudit"={"auditable"=true, "immutable"=true},
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
     * @var \DateTime
394
     *
395
     * @ORM\Column(type="datetime", name="closed_at", nullable=true)
396
     * @ConfigField(
397
     *  defaultValues={
398
     *      "dataaudit"={"auditable"=true, "immutable"=true},
399
     *      "importexport"={"excluded"=true, "immutable"=true}
400
     *  }
401
     * )
402
     */
403
    protected $closedAt;
404
405
    /**
406
     * @return int
407
     */
408
    public function getId()
409
    {
410
        return $this->id;
411
    }
412
413
    /**
414
     * @param  Lead        $lead
415
     * @return Opportunity
416
     */
417
    public function setLead($lead)
418
    {
419
        $this->lead = $lead;
420
421
        return $this;
422
    }
423
424
    /**
425
     * @return Lead
426
     */
427
    public function getLead()
428
    {
429
        return $this->lead;
430
    }
431
432
    /**
433
     * @param  float       $budgetAmount
434
     * @return Opportunity
435
     */
436
    public function setBudgetAmount($budgetAmount)
437
    {
438
        $this->budgetAmount = $budgetAmount;
439
440
        return $this;
441
    }
442
443
    /**
444
     * @return float
445
     */
446
    public function getBudgetAmount()
447
    {
448
        return $this->budgetAmount;
449
    }
450
451
    /**
452
     * @param  \DateTime   $closeDate
453
     * @return Opportunity
454
     */
455
    public function setCloseDate($closeDate)
456
    {
457
        $this->closeDate = $closeDate;
458
459
        return $this;
460
    }
461
462
    /**
463
     * @return \DateTime
464
     */
465
    public function getCloseDate()
466
    {
467
        return $this->closeDate;
468
    }
469
470
    /**
471
     * @param  Contact     $contact
472
     * @return Opportunity
473
     */
474
    public function setContact($contact)
475
    {
476
        $this->contact = $contact;
477
478
        return $this;
479
    }
480
481
    /**
482
     * @return Contact
483
     */
484
    public function getContact()
485
    {
486
        return $this->contact;
487
    }
488
489
    /**
490
     * @param  string      $customerNeed
491
     * @return Opportunity
492
     */
493
    public function setCustomerNeed($customerNeed)
494
    {
495
        $this->customerNeed = $customerNeed;
496
497
        return $this;
498
    }
499
500
    /**
501
     * @return string
502
     */
503
    public function getCustomerNeed()
504
    {
505
        return $this->customerNeed;
506
    }
507
508
    /**
509
     * @param  float       $probability
510
     * @return Opportunity
511
     */
512
    public function setProbability($probability)
513
    {
514
        $this->probability = $probability;
515
516
        return $this;
517
    }
518
519
    /**
520
     * @return float
521
     */
522
    public function getProbability()
523
    {
524
        return $this->probability;
525
    }
526
527
    /**
528
     * @param  string      $proposedSolution
529
     * @return Opportunity
530
     */
531
    public function setProposedSolution($proposedSolution)
532
    {
533
        $this->proposedSolution = $proposedSolution;
534
535
        return $this;
536
    }
537
538
    /**
539
     * @return string
540
     */
541
    public function getProposedSolution()
542
    {
543
        return $this->proposedSolution;
544
    }
545
546
    /**
547
     * @param  string      $name
548
     * @return Opportunity
549
     */
550
    public function setName($name)
551
    {
552
        $this->name = $name;
553
554
        return $this;
555
    }
556
557
    /**
558
     * @return string
559
     */
560
    public function getName()
561
    {
562
        return $this->name;
563
    }
564
565
    /**
566
     * @param  OpportunityCloseReason $closeReason
567
     * @return Opportunity
568
     */
569
    public function setCloseReason($closeReason)
570
    {
571
        $this->closeReason = $closeReason;
572
573
        return $this;
574
    }
575
576
    /**
577
     * @return OpportunityCloseReason
578
     */
579
    public function getCloseReason()
580
    {
581
        return $this->closeReason;
582
    }
583
584
    /**
585
     * @param float $revenue
586
     */
587
    public function setCloseRevenue($revenue)
588
    {
589
        $this->closeRevenue = $revenue;
590
    }
591
592
    /**
593
     * @return float
594
     */
595
    public function getCloseRevenue()
596
    {
597
        return $this->closeRevenue;
598
    }
599
600
    /**
601
     * @return \DateTime
602
     */
603
    public function getCreatedAt()
604
    {
605
        return $this->createdAt;
606
    }
607
608
    /**
609
     * @param  \DateTime   $created
610
     * @return Opportunity
611
     */
612
    public function setCreatedAt($created)
613
    {
614
        $this->createdAt = $created;
615
616
        return $this;
617
    }
618
619
    /**
620
     * @return \DateTime
621
     */
622
    public function getUpdatedAt()
623
    {
624
        return $this->updatedAt;
625
    }
626
627
    /**
628
     * @param  \DateTime   $updated
629
     * @return Opportunity
630
     */
631
    public function setUpdatedAt($updated)
632
    {
633
        $this->updatedAt = $updated;
634
635
        return $this;
636
    }
637
638
    /**
639
     * Get the primary email address of the related contact
640
     *
641
     * @return string
642
     */
643
    public function getEmail()
644
    {
645
        $contact = $this->getContact();
646
        if (!$contact) {
647
            return null;
648
        }
649
650
        return $contact->getEmail();
651
    }
652
653
    public function __toString()
654
    {
655
        return (string) $this->getName();
656
    }
657
    /**
658
     * @ORM\PrePersist
659
     */
660
    public function beforeSave()
661
    {
662
        $this->createdAt = new \DateTime('now', new \DateTimeZone('UTC'));
663
        $this->beforeUpdate();
664
    }
665
666
    /**
667
     * @ORM\PreUpdate
668
     */
669
    public function beforeUpdate()
670
    {
671
        $this->updatedAt = new \DateTime('now', new \DateTimeZone('UTC'));
672
    }
673
674
    /**
675
     * @return User
676
     */
677
    public function getOwner()
678
    {
679
        return $this->owner;
680
    }
681
682
    /**
683
     * @param  User        $owningUser
684
     * @return Opportunity
685
     */
686
    public function setOwner($owningUser)
687
    {
688
        $this->owner = $owningUser;
689
690
        return $this;
691
    }
692
693
    /**
694
     * @return string
695
     */
696
    public function getNotes()
697
    {
698
        return $this->notes;
699
    }
700
701
    /**
702
     * @param  string      $notes
703
     * @return Opportunity
704
     */
705
    public function setNotes($notes)
706
    {
707
        $this->notes = $notes;
708
709
        return $this;
710
    }
711
712
    /**
713
     * @param B2bCustomer $customer
714
     * @TODO remove null after BAP-5248
715
     */
716
    public function setCustomer(B2bCustomer $customer = null)
717
    {
718
        $this->customer = $customer;
719
    }
720
721
    /**
722
     * @return B2bCustomer
723
     */
724
    public function getCustomer()
725
    {
726
        return $this->customer;
727
    }
728
729
    /**
730
     * Set organization
731
     *
732
     * @param Organization $organization
733
     * @return Opportunity
734
     */
735
    public function setOrganization(Organization $organization = null)
736
    {
737
        $this->organization = $organization;
738
739
        return $this;
740
    }
741
742
    /**
743
     * Get organization
744
     *
745
     * @return Organization
746
     */
747
    public function getOrganization()
748
    {
749
        return $this->organization;
750
    }
751
752
    /**
753
     * Remove Customer
754
     *
755
     * @return Lead
756
     */
757
    public function removeCustomer()
758
    {
759
        $this->customer = null;
760
    }
761
762
    /**
763
     * @param \DateTime $closedAt
764
     */
765
    public function setClosedAt(\DateTime $closedAt = null)
766
    {
767
        $this->closedAt = $closedAt;
768
    }
769
770
    /**
771
     * @return \DateTime
772
     */
773
    public function getClosedAt()
774
    {
775
        return $this->closedAt;
776
    }
777
}
778